The “Npm cannot find module npm-cli.js error” occurs, when there are problems with the installation or misconfiguration of Node.js and npm on your system.
To resolve the error, it is recommended to reinstall Node.js and npm, ensure proper environment variable settings, check for global package conflicts, and resolve any permission-related issues.
Npm Cannot find module npm-cli.js error
Here are 3 simple approaches for that:
Approach 1: Repair the Node.js
Here are steps to repair node js:
- Go to “Add or Remove Programs” in the Control Panel.
- Locate “Node.js” in the list of installed programs.
- Click on it and select “repair.”
Approach 2: Add Node and NPM PATH to the System environment variable
Here are the steps to set NPM and Node.js paths manually:
- Locate Node.js Installation Directory: Find the directory where Node.js is installed on your system. The default installation path is often
C:\Program Files\nodejs
on Windows. - Locate NPM Installation Directory: Similarly, locate the directory where npm is installed. It’s typically found within the Node.js installation directory, such as
C:\Program Files\nodejs\node_modules\npm
on Windows. - Copy Node.js and NPM Paths: Copy the paths of the Node.js and npm executable files. These files are usually named
node.exe
andnpm.cmd
. For example:- Node.js Path:
C:\Program Files\nodejs\node.exe
- NPM Path:
C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
- Node.js Path:
- Open System Properties: Right-click on the
This PC
orComputer
icon on your desktop or in the File Explorer, selectProperties
. - Access Advanced System Settings: In the System Properties window, click on the
Advanced system settings
on the left-hand side. - Open Environment Variables: In the System Properties window, click on the
Environment Variables
button. - Edit Path Variable: In the Environment Variables window, under the “System variables” section, find the
Path
variable, and click onEdit
. - Add Node.js and NPM Paths: In the Edit Environment Variable window, click
New
and paste the paths you copied in step 3. ClickOK
to close each window. - Verify Installation: Open a new command prompt and run the following commands to verify that Node.js and npm are accessible:
An alternative way to do this is to type this command on cmd or command prompt and hit enter, this command will add node js path to the PATH system environment variable path:
SET PATH=C:\Program Files\Nodejs;%PATH%
Approach 3: Reinstall Node js and NPM
Still, the error was not resolved. So you can use this last approach. In this, you will first have to uninstall node.js and reinstall it.
Here are the steps on how to uninstall Node.js on Windows:
- Open the Control Panel.
- Click on Programs and Features.
- Look for Node.js in the list of programs.
- Click on Uninstall.
To install Node.js on Windows 11|10, you can try these steps:
- Download the Windows installer from www.Nodejs.org
- Run the installer
- Follow the prompts
- Accept the license agreement
- Accept the default installation settings
- Restart your computer
- Double-click to install .msi binary files
- Verify the installation by opening a command prompt or PowerShell and entering
node -v
Conclusion
Through this tutorial, you see 3 approaches to fix the “Npm Cannot find module npm-cli.js error”, I hope your error is resolved.