Webpack loader that adds export statements to source files that lack them. Current stable version is 5.0.0 (Jan 2024), requiring Node.js >=18.12.0 and webpack^5.0.0. Commonly used for shimming legacy scripts, vendor files, or modules that do not expose exports. Supports inline query configuration and webpack rule options to generate named or default ES module exports (default) or CommonJS module.exports. Key differentiator: declarative, composable with other loaders; simpler than writing wrapper modules. No security incidents reported.
npm install exports-loaderVerified import paths — ran on the pinned version, not inferred.
Shows webpack config rule using exports-loader to add a default export to a legacy script, then importing it in modern code.
Update to Node.js >=18.12.0 or use v4.0.0 if locked to Node 14/16.
Upgrade webpack to v5 or stick to v1.x if on webpack 4. For inline syntax, replace [] with | (e.g., exports[]=myFunc -> exports=named|myFunc).
Use pipe-separated syntax: 'exports=myFunc' for named (shorthand) or 'exports=named|myFunc'.
Add ?type=commonjs to inline query or set options.type: 'commonjs' in webpack config rule.
Ensure source file has no exports or use exports-loader only on files that truly lack exports. Alternatively, use a shim or wrapper module.
Use require.resolve() in test to match exact file path, or use a more specific regex (e.g., include file path anchor).
Ensure the file is valid JavaScript. If using inline syntax, check query string syntax. Try adding additional loaders (e.g., babel-loader) before exports-loader.
Add ?type=commonjs to inline query or set type: 'commonjs' in webpack config options.
Run npm install exports-loader --save-dev or yarn add -D exports-loader.
In v2+, options.exports should be a string or array of strings. For inline syntax, use query parameter 'exports=...'. Check documentation.