django-webpack / webpack-bundle-tracker

Spits out some stats about webpack compilation process to a file
MIT License
266 stars 107 forks source link

ERR_REQUIRE_ESM Build failure after some other package in my app installed new strip-ansi #121

Closed dmt0 closed 8 months ago

dmt0 commented 9 months ago

I'm on 3.0. Error log:

[webpack-cli] Failed to load '/webapp/webpack.config.js' config
[webpack-cli] Error [ERR_REQUIRE_ESM]: require() of ES Module /webapp/node_modules/strip-ansi/index.js from /webapp/node_modules/webpack-bundle-tracker/lib/index.js not supported.
Instead change the require of /webapp/node_modules/strip-ansi/index.js in /webapp/node_modules/webpack-bundle-tracker/lib/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/webapp/node_modules/webpack-bundle-tracker/lib/index.js:23:19)
    at Object.<anonymous> (/webapp/webpack.config.js:5:23)
    at async WebpackCLI.tryRequireThenImport (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:232:34)
    at async loadConfigByPath (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1406:27)
    at async WebpackCLI.loadConfig (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1515:38)
    at async WebpackCLI.createCompiler (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1781:22)
    at async WebpackCLI.runWebpack (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1877:20)
    at async Command.<anonymous> (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:944:21)
    at async Command.parseAsync (/webapp/node_modules/webpack-cli/node_modules/commander/lib/command.js:935:5)
    at async Command.<anonymous> (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1356:13)
    at async Command.parseAsync (/webapp/node_modules/webpack-cli/node_modules/commander/lib/command.js:935:5)
    at async WebpackCLI.run (/webapp/node_modules/webpack-cli/lib/webpack-cli.js:1360:9)
    at async runCLI (/webapp/node_modules/webpack-cli/lib/bootstrap.js:9:9) {
  code: 'ERR_REQUIRE_ESM'
fjsj commented 9 months ago

@dmt0 what's your webpack version?

dmt0 commented 9 months ago

5.89.0

fjsj commented 9 months ago

Can you check which version of strip-ansi you have in your package.json or package-lock.json? Perhaps your project is using the version 7, which isn't compatible with require imports this library uses. If that's the case, we can avoid this dependency by manually embedding in the code the ansi-regex: https://github.com/chalk/strip-ansi/blob/main/index.js https://github.com/chalk/ansi-regex/blob/main/index.js

Contributions are welcome!

dmt0 commented 9 months ago

Yeah, that's correct. I did an update and one of my other dependencies installed version 7. I had to roll back the updates and it's all good.

fjsj commented 9 months ago

Good to know the issue is resolved for you! I will leave this open so we can avoid this dependency in the future.

dmt0 commented 9 months ago

Well, it's not really resolved, since I can't update certain packages. Also more dependencies will switch to strip-ansi v7 over time, and you'll probably have more people come to chime in here.