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.

[webpack-cli] Error: Cannot find module 'acorn'

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
ricardofreemancommented, Apr 26, 2022

Deleting package-lock.json worked for me

1reaction
letmaikcommented, Jan 8, 2022

That is how package manager works, we can’t fix it here, sorry, try to update package manager

npm 8.3.0 (which I used) is already the latest version.

or report them

Sure, any more clues on what it could be and what I should include in the report?

also checvk your resolution field in package.json and try to reinstall deps, maybe they are corrupted

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, deleting package-lock.json etc., didn’t help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module acorn.js - Stack Overflow
I got some error message 'Cannot find module ..\acorn.js' when write 'npm start'. enter image description here. package.json
Read more >
Cannot find module 'webpack-cli' error | bobbyhadz
To solve the "Cannot find module 'webpack-cli'" error, make sure to install webpack-cli globally by running the npm i -g webpack-cli command and...
Read more >
[webpack-cli] Error: Cannot find module 'webpack' - sage
I found some threads that said update node.js. I updated from v12 to v14.16.0, but I dont think that is the issue. Here...
Read more >
acorn - npm
Acorn. A tiny, fast JavaScript parser written in JavaScript. Community. Acorn is open source software released under an MIT license.
Read more >
Laravel-mix cannot find module 'acorn-dynamic-import'
Error : Cannot find module 'acorn-dynamic-import' at Function.Module. ... --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js` npm ERR!
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