[Solved] Error: Cannot find module ‘../lib/cli.js’

If you try and run npm i and get Error: Cannot find module '../lib/cli.js', then you can easily fix the problem by running the following.

How does the error look?

Error: Cannot find module '../lib/cli.js' Require stack: - /usr/local/lib/node_modules/npm/bin/npm-cli.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:999:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:1) at Module._compile (node:internal/modules/cjs/loader:1095:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/local/lib/node_modules/npm/bin/npm-cli.js' ] }
Code language: Bash (bash)

How to solve the Module Not Found error

brew uninstall --ignore-dependencies node sudo chown -R $(whoami) /usr/local/* brew cleanup brew install node
Code language: Bash (bash)

This will uninstall and cleanup your previous node installation, making sure to set the correct permissions, before reinstalling it.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments