question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filename with .js extension fails in webpack@5

See original GitHub issue

Versions:

  • 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:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ryan-roemercommented, Oct 29, 2022

Fix released in webpack-stats-plugin@1.1.1

1reaction
ryan-roemercommented, Oct 28, 2022

OK – I have reproduced this one. Weird.

Anyways, issue is verified and I’ll look in further. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found