[webpack-cli] Error: Cannot find module 'acorn'
See original GitHub issueBug report
What is the current behavior?
Running webpack throws an exception that acorn
cannot be found:
[webpack-cli] Error: Cannot find module 'acorn'
Require stack:
- [root]\node_modules\acorn-import-assertions\lib\index.js
- [root]\node_modules\webpack\lib\javascript\JavascriptParser.js
- [root]\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js
- [root]\node_modules\webpack\lib\WebpackOptionsApply.js
- [root]\node_modules\webpack\lib\webpack.js
- [root]\node_modules\webpack\lib\index.js
- [root]\node_modules\webpack-cli\lib\webpack-cli.js
- [root]\node_modules\webpack-cli\lib\bootstrap.js
- [root]\node_modules\webpack-cli\bin\cli.js
- [root]\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> ([root]\node_modules\acorn-import-assertions\lib\index.js:8:38)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'[root]\\node_modules\\acorn-import-assertions\\lib\\index.js',
'[root]\\node_modules\\webpack\\lib\\javascript\\JavascriptParser.js',
'[root]\\node_modules\\webpack\\lib\\javascript\\JavascriptModulesPlugin.js',
'[root]\\node_modules\\webpack\\lib\\WebpackOptionsApply.js',
'[root]\\node_modules\\webpack\\lib\\webpack.js',
'[root]\\node_modules\\webpack\\lib\\index.js',
'[root]\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
'[root]\\node_modules\\webpack-cli\\lib\\bootstrap.js',
'[root]\\node_modules\\webpack-cli\\bin\\cli.js',
'[root]\\node_modules\\webpack\\bin\\webpack.js'
]
}
NOTE: node_modules/webpack/node_modules/acorn
exists, but this is invisible to node_modules/acorn-import-assertions
since it’s at the wrong level (I think).
If the current behavior is a bug, please provide the steps to reproduce.
I need some time to create a repro, let me know if it’s needed.
It seems to happen though when another dependency in the same project has a version-incompatible dependency on acorn
(e.g. 7 instead of 8) leading to acorn
being duplicated and pushed deeper inside the tree.
What is the expected behavior?
Other relevant information: webpack version: 5.65.0 Node.js version: 16.13.1 Operating System: Windows 11 Additional tools: npm 8.3.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (4 by maintainers)
Top GitHub Comments
Deleting
package-lock.json
worked for menpm 8.3.0 (which I used) is already the latest version.
Sure, any more clues on what it could be and what I should include in the report?
I don’t know
resolution
and it’s not specified in https://docs.npmjs.com/cli/v8/configuring-npm/package-json. I tried reinstalling deps, deletingpackage-lock.json
etc., didn’t help.