Filename with .js extension fails in webpack@5
See original GitHub issueVersions:
- webpack@5.74.0
- webpack-stats-plugin@1.1.0
Problem:
To meet the project requirement, I’m supposed to generate stats.js file instead of the default stats.json file. Unfortunately the below setup ended up with an error.
new StatsWriterPlugin({
filename: 'stats.js',
fields: ['entrypoints'],
transform(data) {
const assets = data.entrypoints.main.assets;
const stats = assets.map((asset, index) => {
const order = index + 1;
return {
id: `asset-${order}`,
name: asset.name,
order
};
});
statsStr = JSON.stringify(stats);
return `define('stats',function(){return ${statsStr}});`;
}
})
Error:
[webpack-cli] HookWebpackError: inputSource.sourceAndMap is not a function
at makeWebpackError (/Users/xuser/workspace/my-project/node_modules/webpack/lib/HookWebpackError.js:48:9)
at /Users/xuser/workspace/my-project/node_modules/webpack/lib/Compilation.js:3060:12
at eval (eval at create (/Users/xuser/workspace/my-project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:1)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
-- inner error --
TypeError: inputSource.sourceAndMap is not a function
at /Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/index.js:454:27
at next (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:81:7)
at Array.forEach (<anonymous>)
at /Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:84:26
at new Promise (<anonymous>)
at throttleAll (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:53:10)
at TerserPlugin.optimize (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/index.js:662:11)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
caused by plugins in Compilation.hooks.processAssets
TypeError: inputSource.sourceAndMap is not a function
at /Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/index.js:454:27
at next (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:81:7)
at Array.forEach (<anonymous>)
at /Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:84:26
at new Promise (<anonymous>)
at throttleAll (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/utils.js:53:10)
at TerserPlugin.optimize (/Users/xuser/workspace/my-project/node_modules/terser-webpack-plugin/dist/index.js:662:11)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Tips:
I found curCompiler.webpack at line 157 goes undefined, so I believe source object needs additional property (sourceAndMap).
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
resolve.extensions not working for files different from js, jsx
Like in webpack 4, using file with extension from resolve.extensions list is not leading to error. Other relevant information: webpack version: ...
Read more >Output filename not configured Error in Webpack
I was getting the same error and it turned out to be my webpack config file name. I had it as " webpack.config...
Read more >Resolve | webpack
If multiple files share the same name but have different extensions, webpack will resolve the one with the extension listed first in the...
Read more >Adding Hashes to Filenames - SurviveJS
Cache invalidation can be achieved by including a hash to the filenames. Starting from version 5, webpack is using a deterministic way of...
Read more >How to transpile ES modules with webpack and Node.js
In the JavaScript ecosystem, webpack stands out as a major tool for ... meaning we must append the full filename with their extensions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Fix released in
webpack-stats-plugin@1.1.1OK – I have reproduced this one. Weird.
Anyways, issue is verified and I’ll look in further. Thanks!