Visual Studio Code (VSCode) provides an integrated terminal to run commands inside the current directory. Recently, I installed VSCode and tried to run the NPM commands and it shows following errors:
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:841:27)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m
[90m at internal/main/run_main_module.js:17:47[39m {
code: [32m'MODULE_NOT_FOUND'[39m,
requireStack: []
}
Reasons:
This error could be due to the following reasons:
- The Node/NPM path is not added in the Environment Variable PATH (for Windows)
- You are not running VSCode as an administrator
Solutions:
- To add Node path to the Environment Variable PATH, follow the instructions here
- Change the default shell of Integrated Terminal to Command Prompt.
- Close VSCode and open VSCode as an administrator
- To automatically run VSCode as an administrator, follow the instructions listed here
I hope it will help to resolve these errors. 🙂