NPM Commands Not Working in Integrated Terminal of VSCode

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'
    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: []
}

Reasons:

This error could be due to the following reasons:

  1. The Node/NPM path is not added in the Environment Variable PATH (for Windows)
  2. You are not running VSCode as an administrator

Solutions:

  1. To add Node path to the Environment Variable PATH, follow the instructions here
  2. Change the default shell of Integrated Terminal to Command Prompt.
  3. Close VSCode and open VSCode as an administrator
  4. To automatically run VSCode as an administrator, follow the instructions listed here

I hope it will help to resolve these errors. 🙂

Leave a Comment

Your email address will not be published.