Last updated: Apr 4, 2024
Reading time·4 min
The error "Cannot find module npm-cli.js" occurs when the path to Node.js in
your system's PATH
environment variable is incorrect.
To solve the error, repair the Node.js application and correct the path.
internal/modules/cjs/loader.js:584 throw err; ^ Error: Cannot find module 'C:\Users\Bobbyhadz\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
The first thing you should try is to repair Node.js:
npm --version
command to see if the error is resolved.If the error is not resolved, try to issue the following command in CMD (Command Prompt).
SET PATH=C:\Program Files\Nodejs;%PATH%
If the error persists, you have to correct the path to Node.js in your system's
PATH
environment variable.
If you already have Node.js installed correctly, scroll down to the next subheading.
To install Node and add it to your PATH
environment variable:
Next
on the Welcome screen.Next
.Next
.Next
. Notice that there is an "Add to
PATH" option selected.Next
.Install
button.Finish
button.Make sure to close any existing command prompts and PowerShell instances for
the PATH
variable to get updated.
You can start a new CMD shell and use the npm --version
command to make
sure Node is installed.
npm --version node --version
npm
commands for the PATH variable to update.If you got the error in Visual Studio Code and restarting VSCode doesn't help, try to click on the trash bin button to restart the terminal.
If the error persists, add Node to your PATH environment variable manually.
To add Node to your PATH environment variable:
nodejs
directory is most likely under:C:\Program Files\nodejs
C:\Program Files (x86)\nodejs
node.exe
(executable) file.Next, ensure you also have the path to your npm
directory in the PATH as
well.
Your npm
directory is most likely located under
%USERPROFILE%\AppData\Roaming\npm
, which is the same as
C:\Users\YOUR_USER\AppData\Roaming\npm
.
%USERPROFILE%\AppData\Roaming\npm # 👇️ same as below (make sure to replace YOUR_USER) C:\Users\YOUR_USER\AppData\Roaming\npm
If you can't find it, try running the npm config get prefix
command.
npm config get prefix
Add the path to npm
and click on "OK" twice to confirm.
Close your Command prompt application and then reopen it.
You might also have to restart your PC, but that's not always necessary.
You can start a new CMD shell and use the npm --version
command to make sure
Node is installed and the npm
command works.
npm --version node --version
If you got the error in Visual Studio Code and restarting VSCode doesn't help, try to click on the trash bin button to restart the terminal.
If the error persists, try to run CMD or VSCode as an administrator before
issuing an npm
command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
You can run VS Code as an administrator by right-clicking on VSCode and clicking "Run as administrator".
Try to issue an npm
command with elevated permissions, e.g. npm --version
.
You can learn more about the related topics by checking out the following tutorials: