Webpack - Error: Cannot find module 'node:assert'
Asked Answered
T

5

6

Webpack - Error: Cannot find module 'node:assert'

I tried adding "assert" npm package no luck, any one have any ideas on what is throwing the error?

Turnover answered 15/2, 2022 at 14:2 Comment(2)
Are you sure you were trying to install the 'assert' package? (e.g npm install assert) Cause I see you have an error regarding the node:assert package. If it does not work try updating the webpack.config.js and include the assert in the fallback section (this applies to webpack 5)Leesa
yeah, i tracked down the issue to a build env conflict with netlify plugin that was manifesting this error, ty!Turnover
A
29

Please update node.js to latest versions and that should fix the issue for NX projects

Apathetic answered 22/11, 2022 at 15:47 Comment(2)
updated node.js to 16.16.0 and this fixed the issue for me. thanksIvory
Spot on here 16.16.0 worked for me too, It's a shame that the errors aren't so intuitive.Clarey
S
3

Another thing is if you are using typescript like me, then:

npm i @types/node

And make sure the the tsconfig.json doesn't have a custom typeRoots property that ignores the default types in the node_modules folder

Spermogonium answered 30/1, 2023 at 8:56 Comment(1)
that was my issue, bumped version from v12 to v14 and later to v16Cleavable
M
2

It occurs when you have an old Node version on your system and a new package is being used in your project, and you receive this error during the compilation process.

Below Solution works for me:

Step: 1 - Uninstall nodejs older version

Step: 2 - Install new version of nodejs. (https://nodejs.org/en/download)

Step: 3 - Remove node_module from the current project

Step: 4 - Run npm i and re-compile your project again

Before:

enter image description here

After:

enter image description here

Mysticism answered 16/4, 2023 at 8:29 Comment(0)
S
1

I had the same issue on my macOS Monterey (Apple M1), I tried updating node, using npm & homebrew

  • updating with npm didn't work
  • updating with homebrew showed an updated status, but when I checked via intellij terminal (node -v) it still returned the old version.

Resolved by running "nvm install node" within intellij's terminal in the project directory.

Selfservice answered 21/3, 2023 at 20:40 Comment(0)
A
0
rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm install

I use the above command, it was really helpful

Appanage answered 8/10 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.