Error cannot find module npm cli js

Usually I can install a library using npm but today when installing yeoman I encountered this errors. Please help to figure out what's root cause. D:Worksphonegapionictodo>npm install -g yo...

Usually I can install a library using npm but today when installing yeoman I encountered this errors. Please help to figure out what’s root cause.

D:Worksphonegapionictodo>npm install -g yo
    module.js:340
    throw err;
          ^
Error: Cannot find module 'C:Program Filesnodejsnode_modulesnpmbinnode_modulesnpmbinnpm-cli.js'

at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

I looked into the folder:

C:Program Filesnodejsnode_modulesnpmbin

but don’t see node_modules folder as the error described.

I also try to find npm-cli.js and see it’s actually in C:Program Filesnodejsnode_modulesnpmbin

Promise Preston's user avatar

asked Jul 13, 2014 at 10:52

user1192476's user avatar

4

It turns out the issue is due to the wrong path of node in system variable. The path is currently pointing to

(I really don’t know when I modified it)

C:Program Filesnodejsnode_modulesnpmbin

so I change to

C:Program Filesnodejs

and it works like a charm.

CodeWizard's user avatar

CodeWizard

121k21 gold badges138 silver badges162 bronze badges

answered Jul 14, 2014 at 16:56

user1192476's user avatar

user1192476user1192476

3,0553 gold badges15 silver badges9 bronze badges

9

You need to run this in the command line.

SET PATH=C:Program FilesNodejs;%PATH%

Pang's user avatar

Pang

9,344146 gold badges85 silver badges121 bronze badges

answered Feb 29, 2016 at 23:45

Prathap Kudupu's user avatar

4

I just repaired my NodeJS installation and it worked for me!

Go to Control PanelAll Control Panel ItemsPrograms and Features —> find NodeJS and choose option repair to repair it. Hope this helps.

answered Mar 26, 2018 at 8:59

3AK's user avatar

3AK3AK

1,09313 silver badges22 bronze badges

7

You may also have this problem if in your path you have C:Program Filesnodejs and C:Program Filesnodejsnode_modulesnpmbin. Remove the latter from the path

Rory McCrossan's user avatar

answered Jul 2, 2015 at 19:42

Peter Sun's user avatar

Peter SunPeter Sun

2913 silver badges2 bronze badges

1

Copy the directory named npm from your installed node path (In my case the npm directory was available in C:Program Filesnodejsnode_modules).

Navigate to C:Users%USERNAME%AppDataRoamingnpmnode_modules and paste the copied npm directory there.

This method worked for me when I had the same error. . .

MBehtemam's user avatar

MBehtemam

7,69513 gold badges62 silver badges106 bronze badges

answered Jul 7, 2018 at 12:15

Manoj's user avatar

ManojManoj

7348 silver badges7 bronze badges

2

This not the same case as in the question, but might be helpful for someone facing the similar issue. On Windows, if you are calling npm commands from some CI/automation tool, you might run into the error:

Error: Cannot find module 'SOME_PATHnode_modulesnpmbinnpm-cli.js'

where SOME_PATH is not Program Files/... but some project directory instead. So npm tries to find npm-cli.js inside the project root directory instead of searching it in Program Files/nodejs.

The reason is npm.cmd script:

:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)


SET "NPM_CLI_JS=%~dp0node_modulesnpmbinnpm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%Fnode_modulesnpmbinnpm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

This script uses %~dp0 to lookup the npm-cli.js but some automation tools could set work directory in the way that %~dp0 points to the local project dir so the script works incorrectly.

One possible solution could be changing the npm calls from this

npm.cmd install

to this

cmd.exe /c npm.cmd install

answered Jun 29, 2017 at 8:46

admax's user avatar

admaxadmax

1,6532 gold badges16 silver badges23 bronze badges

2

I encountered the same problem with node 8.5 when installed with nvm. The below solution worked for me

$ nvm uninstall 8.5
8.5.0
Uninstalling node v8.5.0...Error removing node v8.5.0
Manually remove C:UsersOmkarAppDataRoamingnvmv8.5.0.

$ nvm install 8.5
8.5.0
Downloading node.js version 8.5.0 (64-bit)...
Complete
Creating C:UsersOmkarAppDataRoamingnvmtemp

Downloading npm version 5.3.0... Complete
Installing npm v5.3.0...

Installation complete. If you want to use this version, type

nvm use 8.5.0

Omkar@VAST-0137 MINGW64 /d/code

This worked for me cause node 8.5 was not correctly installed before with nvm. I figured it out cause «npmbinnpm-cli.js» folders and files were not created inside node_modules before.

answered Mar 29, 2018 at 19:24

olagu's user avatar

olaguolagu

5575 silver badges10 bronze badges

3

This started happening for me after I installed GoogleChrome/puppeteer, the solution was to re-install npm:

$ npm i npm@latest

or

$ npm install npm@latest

Daniel Fisher  lennybacon's user avatar

answered Mar 20, 2018 at 2:41

mythz's user avatar

mythzmythz

141k29 gold badges241 silver badges385 bronze badges

1

None of the other answers worked for me.

Here is what I write (in a git bash shell on windows ):

PATH="/c/Program Files/nodejs/:$PATH" npm run yeoman

answered Apr 12, 2016 at 9:26

edi9999's user avatar

edi9999edi9999

19k13 gold badges88 silver badges127 bronze badges

0

On a Mac:

I was running this out of the Maven com.github.eirslett Frontend Plugin when I had the same error.

Eventually I had to:

Install Node.js via the installer download here: http://nodejs.org/

Delete all the node/ and node_modules/ folders from within my maven build structure.

answered Nov 14, 2014 at 17:00

RedYeti's user avatar

RedYetiRedYeti

1,00214 silver badges28 bronze badges

2

In addition to above I had to remove C:Users%USERNAME%AppDataRoamingnpm also.
This helped.

answered Dec 31, 2016 at 14:01

Romko's user avatar

RomkoRomko

1,80020 silver badges27 bronze badges

1

Don’t change any environment variables

It was the installer which caused the issue and did not install all the required file.

I just repaired the NODEJS setup on windows 7 and it works very well. May be you can reinstall, just incase something does not work.

answered Jan 3, 2018 at 11:09

TARJU's user avatar

TARJUTARJU

1,6851 gold badge14 silver badges14 bronze badges

There are actually 2 paths which was added to your System’s Variable when upgrading to nodejs latest version.
1. C:Program Filesnodejs
2. C:Program Filesnodejsnode_modulesnpmbin
For windows 7/8/8.1 users, they will not have an Environment Variables Windows 10 smart GUI.
Anyway, all you have to do is search for "C:Program Filesnodejsnode_modulesnpmbin" and remove it.
Also, remove "C:Users%USERNAME%AppDataRoamingnpm" from your environment variables. I am posting this answer because I wasted my 10hrs searching for the solution on internet. By combining the above answer I finally make it through the problem.

answered Aug 31, 2017 at 12:42

haMzox's user avatar

haMzoxhaMzox

2,0831 gold badge12 silver badges23 bronze badges

I had the same issue on windows.
I just repaired Node and it worked fine after a restart of the command on windows.

answered Dec 11, 2018 at 2:20

Hello Universe's user avatar

Hello UniverseHello Universe

3,1847 gold badges49 silver badges85 bronze badges

On Windows 10:

  1. Press windows key, type edit the system environment variables then enter.
  2. Click environment variables…
  3. On the lower half of the window that opened with title Environment Variables there you will see a table titled System Variables, with two columns, the first one titled variable.
  4. Find the row with variable Path and click it.
  5. Click edit which will open a window titled Edit evironment variable.
  6. Here if you find

C:Program Filesnodejsnode_modulesnpmbin

select it, and click edit button to your right, then edit the field to the path where you have the nodejs folder, in my case it was just shortening it to :

C:Program Filesnodejs

Then I closed all my cmd or powershell terminals, opened them again and npm was working.

answered Oct 6, 2019 at 14:40

Julio Peguero's user avatar

None of the solutions here worked for me but after I restarted my system and did npm install again, it worked.
I would guess one or more processes I ran before held unto it.

Simple PC restart on Windows 10 did the magic for me!

answered Feb 2, 2018 at 20:44

papigee's user avatar

papigeepapigee

5,8733 gold badges26 silver badges30 bronze badges

1

In my case, I was using nvm-windows 1.1.6 , and I updated my nodejs version using nvm install latest, which eventually told me that nodejs and npm are installed, however when I tried to do npm install, I received

Error: Cannot find module ‘C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js’

upon checking nvm-windows structure, I found that C:Program Filesnodejs was symlinked to %APPDATA%nvmNODE_VERSION, (NODE_VERSION was v9.7.1 in my case) which has the folder node_modules having nothing inside, caused this error. The solution was to copy the npm folder from one of my previous versions’ node_modules folder and paste it in. I then updated my npm with npm install npm@next -g and everything started working again.

answered Mar 4, 2018 at 20:32

Cemal's user avatar

CemalCemal

1,4291 gold badge11 silver badges19 bronze badges

I know it is an older post but as I write this the version of Node js is 12.13.1. People face this generally because they might have already installed a previous version of Node js which added the following to the system path.

C:Program Filesnodejsnode_modulesnpmbin

However, the newer versions need to add the following:-

C:Program Filesnodejs

I mean to say the path where you installed the Nodejs. The default is

C:Program Filesnodejs

However, if you gave a different location you should point it to that.

answered Nov 27, 2019 at 9:06

Dhana's user avatar

DhanaDhana

4651 gold badge8 silver badges26 bronze badges

just run this command :

npm i npm@latest -g

answered Jul 27, 2018 at 23:07

AissaDevLab's user avatar

AissaDevLabAissaDevLab

4645 silver badges6 bronze badges

2

npm install -g npm@[version] fixed the problem

answered Mar 11, 2019 at 12:29

repo's user avatar

reporepo

7281 gold badge8 silver badges19 bronze badges

For guys still coming around this thread:

  • install node from official site (check npm and node version to check
    whether installed properly, yes in a new terminal/cmd);
  • install nvm now and when prompt to whether manage current node with nvm click yes;
  • open new cmd and run nvm on.

Marco Lackovic's user avatar

answered Sep 3, 2019 at 11:27

Keshav Sharma's user avatar

1

Solution for me in VS2017 (Under Tools | Options … )

Under Tools | Options ...

I changed the path to: C:Program Filesnodejs

answered Oct 10, 2017 at 8:54

Michael Maier's user avatar

I run into this problem when installing node9.0.0 on windows7
at the end the solution was to just remove
npm
npm.cmd
npx
npx.cmd
from
C:Program Filesnodejsnode_modulesnpmbin
before doing this a workaround was to run
C:Program Filesnodejsnpm
so that is one way so see if you have the same problem I had.

answered Nov 2, 2017 at 12:37

Griffin's user avatar

GriffinGriffin

7185 silver badges12 bronze badges

create a npm folder manually inside node_modules and rerun the installer with repair options. It copies the missing files.

answered Jan 20, 2018 at 21:01

Saurabh Nainwal's user avatar

For me none of the above worked, I just noticed that every time I do a «npm install…» any npm command just stop working.
So every install I do, I have to run the NodeJS installation programme and select «repair».
Until I find a real solution :)

answered Mar 25, 2018 at 19:42

Olivier's user avatar

1

Updating NPM to the latest version worked for me:

npm install npm@latest -g

double-beep's user avatar

double-beep

4,85916 gold badges32 silver badges41 bronze badges

answered Jul 14, 2019 at 16:11

zylo's user avatar

zylozylo

4637 silver badges12 bronze badges

Change the environment path variable
C:Program Filesnodejsnode_modulesnpmbin
and open the command terminal and npm -v and

answered Sep 3, 2019 at 19:12

lokesh sharma's user avatar

I encountered the exact same problem today in a Linux server. And the reason is really simple as I didn’t do make install after make and tried to directly call the generated npm. Thus the PATH and everything was a mess.

So for me, the solution is just to do make install after make and run the npm under .node/bin/npm.

answered May 12, 2020 at 8:07

Yuan Tao's user avatar

Yuan TaoYuan Tao

4375 silver badges7 bronze badges

Error: Cannot find module ‘C:Program Filesnodejsnode_modulesnpmbinnode_modulesnpmbinnpm-cli.js’

Look at the above and it is obvious that the path has issue.
‘C:Program Filesnodejsnode_modulesnpmbinnode_modulesnpmbinnpm-cli.js’
SHOULD BE CHANGED TO—>
‘C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js’
which means that «node_modulesnpmbin» in between was duplicated, which caused such a stupid error.
I fixed it by editing the System Variable and updated the PATH as described above.

answered Nov 4, 2020 at 15:32

Ben's user avatar

BenBen

1391 silver badge4 bronze badges

Same Issue.

Resolved by copying the missing files from

C:UsersUserNameAppDataRoamingnpmnode_modulesnpmbin

to

C:UsersUserNamenode_modulesnpmbin

The missing files are

  • npm
  • npm.cmd
  • npm-cli.js
  • npx
  • npx.cmd
  • npx-cli.js

answered Dec 5, 2020 at 5:13

Leslie Wong's user avatar

1

Ah, I had a similar problem with the linux-x64 version v10.15.3 on the Ubuntu subsystem for Windows 10, and suspect it is probably the same problem across multiple platform distributions.
The issue is the scripts for npm and npx aren’t even calling the correct files and are also using relative paths incorrectly!

I did the following to fix:

  1. Locate nodejs bin
    Ubuntu Example:
which node
/usr/local/lib/nodejs/node-v10.15.3-linux-x64/bin/node
  1. Navigate to NodeJS bin
    Ubuntu Example:
cd /usr/local/lib/nodejs/node-v10.15.3-linux-x64/bin
  1. View the problematic scripts
    Ubuntu Example:
cat npm
../lib/node_modules/npm/bin/npm-cli.js

cat npx
../lib/node_modules/npm/bin/npx-cli.js
  1. Shake/smack head
    Ubuntu Example:
  1. Rename (or remove) the bad files
    Ubuntu Example:
mv npm npm-wrong

mv npx npx-wrong
  1. Replace bad files with relative symbolic links to the correct locations
    Ubuntu Example:
ln -s ../lib/node_modules/npm/bin/npm npm

ln -s ../lib/node_modules/npm/bin/npx npx
  1. Also add a symbolic link to the node_modules directory itself, because another broken reference occurs without it
    Ubuntu Example:
ln -s ../lib/node_modules/ node_modules
  1. Test
    Ubuntu Example:
cd ../../..

pwd
/usr/local/lib

npm version
{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.3',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.51',
  zlib: '1.2.11' }
  1. Post about discovery on Github Issue Tracker
    Example:
    Error: Cannot find module ‘C:Program Filesnodejsnode_modulesnpmbinnode_modulesnpmbinnpm-cli.js’ #1618 (comment)

Содержание

  1. Can’t run npm on node 18.12.1 on Linux #45329
  2. Comments
  3. Version
  4. Platform
  5. Subsystem
  6. What steps will reproduce the bug?
  7. How often does it reproduce? Is there a required condition?
  8. What is the expected behavior?
  9. What do you see instead?
  10. Additional information
  11. Version
  12. Platform
  13. Subsystem
  14. What steps will reproduce the bug?
  15. How often does it reproduce? Is there a required condition?
  16. What is the expected behavior?
  17. What do you see instead?
  18. Additional information
  19. Cannot find module ‘..node_modulesnpmbinnpm-cli.js’ when running «gradlew -Pprod bootRepackage» #1829
  20. Comments
  21. Unable to find npm-cli in node-modules folder #636
  22. Comments
  23. My Environment
  24. Expected Behavior
  25. Actual Behavior
  26. Edit: Maybe this extra context will help developers.

Can’t run npm on node 18.12.1 on Linux #45329

Version

18.12.1 (the archive downloaded directly from site)

Platform

Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

What steps will reproduce the bug?

How often does it reproduce? Is there a required condition?

What is the expected behavior?

What do you see instead?

Additional information

When I edit node-v18.12.1-linux-x64/bin/npm from:

The problem will be solved. But I don’t how to make contribution, because I can’t understand your source code.

The text was updated successfully, but these errors were encountered:

Can we try rm -rf node_modules/ && npm I and please paste the results for better debugging.

Also, is it possible to make a test code snippet?

Got this too. Such issues do not occur on nvm or nodesource, only with archive downloaded directly from site.
Devs must be joking. I simply download archive, untar it in /opt/, set PATH to /opt/node/bin.

node —version is working

npm only works with change above

npx also needs a patch:

Sorry, I am dumb fox, looks like false alert

When I leave node binary archive in /home and rename it to node19 it works just fine. This is what I have in .bashrc:

having it in /opt with root owner and 755 produces issues above. How should I set permissions correctly?

Version

Platform

Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

What steps will reproduce the bug?

How often does it reproduce? Is there a required condition?

What is the expected behavior?

What do you see instead?

Additional information

When I edit node-v18.12.1-linux-x64/bin/npm from:

The problem will be solved. But I don’t how to make contribution, because I can’t understand your source code.

I also have this issue

Hello! I`m trying to deploy nodejs app on AWS ubuntu EC2 micro instance. I have Node 18.12.1. When I start from my local folder in the remote terminal — it works well. But when I run as a demon — node throws an error where I use an ‘import’ statament. When I reconfiged a package.json file — the app works well

I have the same problem on a PC on Windows . After update Node version. Can any fixed this problem?

I had the same issue running rm -rf node_modules && npm i fixed it for me.

Источник

Cannot find module ‘..node_modulesnpmbinnpm-cli.js’ when running «gradlew -Pprod bootRepackage» #1829

I am new to this, so please bare with me. What I am doing is trying to deploy my jhipster code. For that I need to build war file. So I run the command gradlew -Pprod bootRepackage in command prompt. My project has no node_modules folder and so it is throwing error : Cannot find module ‘..node_modulesnpmbinnpm-cli.js’ .

The text was updated successfully, but these errors were encountered:

This is an NPM installation problem, not a JHipster bug.

Have a look at the NPM documentation, you have nice videos etc: https://docs.npmjs.com/

But why is it looking for node_modules folder in my project instead of the global folder where npm is installed?

If your project has no node_modules folder, it’s because the install phase after generation did no succeed or you did not follow the procedure in our doc.
Run it manually:

Got It @gmarziou . Actually I created the Jhipster project on a different machine and committed the code to be run on my machine. Now node_modules folder path is in .gitignore, so not committed. Should I remove the node_modules from .gitignore and recommit or I have to run npm on my machine again?

If node_modules is not existing ./gradlew -Pprod bootRepackage executes npm install , so you should keep node_modules ignored. Which version of the generator are you using? Which operating system are you using?

All Right. I am using windows and the latest version of Jhipster: 2.19.0

I ran the following command on windows cmd: gradlew -Pprod bootRepackage. It Build Successfully but it did not generate any node_modules folder.

Okay, I can’t check it now on windows. @deepu105 Can you try it? But it sounds like a npm missconfiguration.

One more thing. If I run yo jhipster:cloudfoundry from windows it gives error: The goal you specified requires a project to execute but there is no POM in this Directory. Please verify you invoked maven from the correct directory.

Now since it is supposed to be a gradle build how can we make cf understand this.
I found something here (Can we use this?): https://github.com/cloudfoundry/cf-java-client/blob/master/cloudfoundry-gradle-plugin/README.md

I’ve been having the same issue trying to build on Windows. I was able to figure it out. Put the following in profile_prod.gradle :

Gradle will then download and install node and npm to the project’s node_modules folder before running npm install.

For some reason Gradle is trying to use node/npm in the project’s local npm_modules folder instead of what’s in the PATH. This may be a bug with the Gradle node plugin, but I haven’t done enough investigation to know where the problem lies for sure. See srs/gradle-node-plugin#64

Edit: JHipster 2.20.0 requires at least node 0.12.0 but the plugin will download 0.11.10 by default, so you will need to specify the version. I updated the config to reflect this.

Источник

Unable to find npm-cli in node-modules folder #636

NVM4W version: 1.1.7

My Environment

Windows 10 Enterprise version 20H2 19042.867

Expected Behavior

I want to be able to use NPM

Actual Behavior

npm —version
internal/modules/cjs/loader.js:613 throw err; ^ Error: Cannot find module ‘C:UsersvkotulskyiAppDataRoamingnvmv12.0.0node_modulesnpmbinnpm-cli.js’

The text was updated successfully, but these errors were encountered:

This is the same as issue #476 that was marked as «resolved».

As a workaround, I had to install NodeJS separately from https://nodejs.org/en/download/. Now npm is installed globally into «C:Program Filesnodejs»npm . After installation, I can now switch between different versions of NodeJS using nvm use , though it always uses the globally installed npm .

I’m using yarn as a package manager, so while this workaround is disappointing, I can probably live with it.

Uggh. My workaround did not persist. After another invocation of nvm install , when I next ran npm , it failed in the same way. So once again, I reinstalled 14.16.1 and it worked again.

Same problem here. First time I tried I was behind a corporate firewall (like someone mentioned in the other issue), but the attached screenshot was on a wide-open internet. Seems to me like the biggest issue isn’t that it fails to install npm, it’s that it acts like everything went fine. Some sort of error message would be great!

Setting environment vars HTTP_PROXY and HTTPS_PROXY , then uninstall and re-install worked for me. curl for Windows uses HTTP_PROXY , too.

@Marcuse7 Of what value should I set HTTP_PROXY and HTTPS_PROXY to?
Thank you in advnace.

@Marcuse7 Of what value should I set HTTP_PROXY and HTTPS_PROXY to?
Thank you in advnace.

I am come from China.I must use a proxy to connect github.The value is my local proxy url:port.
If you used powershell, maybe you can set the terminal proxy.

I’m not behind a proxy to access to Internet, and I have the same error. Any other solution?

I ended by uninstalling this package and using Volta

I did some digging into this and, if proxies are not your issue, this may be caused by using nvm to install a new version of node from a non-elevated prompt (either CMD or PowerShell). If this was the issue, you’ll need to uninstall the version of node causing the issue through nvm and reinstall it with nvm under an administrative/elevated prompt. It appears that @Weicocu was correct in that the npm installation is silently failing when it’s not elevated.

I think something is going wrong somewhere here: https://github.com/coreybutler/nvm-windows/blob/master/src/nvm.go#L284-L306. This code moves the dowlonaded NPM sources to C:Program Filesnodejsnode_modulesnpm , and for some reason C:Program Filesnodejsnode_modules ends up being empty.

I tried to reproduce what the source code does, and made it work, that confirms the above.

  1. Install NVM
  2. nvm install ; nvm use (where is the version you want)
  3. Go to https://nodejs.org/dist/index.json and find node of . In the object containing , remember the value of the npm field. Now it’s
  4. Go to https://github.com/npm/cli/archive/ .zip — this will download the missing NPM sources
  5. Unzip the downloaded archive to
  6. Copy to C:ProgramDatanvmv node_modules
  7. Rename C:ProgramDatanvmv node_modules to C:ProgramDatanvmv node_modulesnpm
  8. NPM now works

I ran into this issue after using nvm to install Node 10.16.3 and then Node 14.17.2 on Windows 10 Enterprise (21H1). I had uninstalled an existing version of Node 10 prior to installing nvm .

I was able to resolve it by using nvm to uninstall both versions, and then nvm install Node 14.17.2 first, then Node 10 — that seemed to fix it.

I also tried running cmd.exe as an Administrator, and then using nvm with those privileges, but that didn’t seem to resolve the situation (but maybe it cleared something without my knowledge).

Same problem here. First time I tried I was behind a corporate firewall (like someone mentioned in the other issue), but the attached screenshot was on a wide-open internet. Seems to me like the biggest issue isn’t that it fails to install npm, it’s that it acts like everything went fine. Some sort of error message would be great!

For anyone that would be have this problem. I can say that, in my case i discover that problem is happening when i’m running the installer from a different partition to windows was installed.

So when i reinstall using nvm-setup.exe from C: partition, all is installed an npm is finded without problems. no need to modify enviroment variables in my win10.

I know that this looks crazy, but i think that this can be usefull to developers resolve this issue, or anyone need help for this now.

Having this same issue today, 26 August 2021.
Node installs work fine, but npm does NOT install.
so nvm-windows is not usable.

This line in the current commit source references a URL location from which to download npm zip files during the install process:

var npmBaseAddress = «https://github.com/npm/cli/archive/»

but the URL referenced there is not accessible:
https://github.com/npm/cli/archive/

(EDIT: This appears to be an intermittent GitHub/network issue? Sometimes the archive file can be downloaded from here, with a 302 redirect, but sometimes it fails! It happens often enough to be a problem for quite a few people in several related issue/comments.)

That file location did not currently exist (404) (at the moment of writing).

This is the line that builds the npm URL plus zip file name:

So the current version of nvm go source code is reaching out to this unreachable URL:
https://github.com/npm/cli/archive/v6.14.15.zip

when it could/should be reaching out to this URL (which IS a valid download link):
https://github.com/npm/cli/archive/refs/tags/v6.14.15.zip
(this link seems to be more stable.)

Maybe the npm team (or GitHub?) changed the default location for release/archive zip files for download?

Just speculating here.
Not sure if this is an issue for NPM team to resolve (should they maintain old zip files in an archive)?
Probably better to simply update nvm-windows to reference the «correct» stable URLs for release zip files, with the «/archive/refs/tags/» URL fragment?

It’s also unfortunate the the error handling does not catch this common issue. Maybe during a cleanup/validation step, the code should actually check that the files for node and npm were actually copied to the correct locations and exist? It’s strange that the download method doesn’t throw an error when the file can not be reached via URL (intermittently, I see now).

Ugly work around here.

Using a modification from this comment above:
#636 (comment)

I was able to get nvm versions to work by downloading the «real» npm zip release artifacts from this URL:
https://github.com/npm/cli/archive/refs/tags/v6.14.15.zip
then unzipping contents of the that archive folder (named ex. «cli-6.14.15») and copying those contents to the nvm node version node_modules directory under a new «npm» folder.

On my machine that translated to (when installing into a node v12 installation):
C:UsersAndrew.MurdochAppDataRoamingnvmv12.22.5node_modulesnpm

you will have to rinse and repeat for each separate node installation node_modules folder.

If the changes in my earlier comment made it into a PR for merge. that might solve the problem. Or maybe not as this may be a truly intermittent GitHub download issue, which makes fixing/trapping errors trickier, but not impossible. And even if a stable fix was submitted, it would not be available until a new nvm-windows release was generated.

Not sure it is worth the time as there haven’t been any new releases in quite a long time as referenced here by the author/maintainer:
#565 (comment)

When npm cannot be found, it means one of the following:

  1. The node installation is invalid/corrupt
  2. npm was not fully downloaded or transferred into the node root.
  3. The user lacks appropriate permissions to execute a script.

In most cases, the node installation doesn’t have npm because node wasn’t installed with the appropriate permissions.

In NVM4W 1.1.9, logic was added to retry use if it fails due to permissions. To run nvm use , an account must have permissions to create directory symlinks (not just junctions). In Windows 10, this requires administrative privileges. In Windows 11, the OS still requires these permissions, but enabling developer mode will grant them. NVM4W attempts to run use «as-is». If the command fails with «access denied», NVM4W will automatically and silently re-run the command, this time presenting a UAC prompt. If you don’t accept the UAC prompt or do not have permission to run it, an «access denied» message will be presented. This should help prevent «bad» node installations.

I recommend upgrading to v1.1.9. If you still encounter this issue, reinstall the version of Node you want to run. The new version should handle these errors.

I’m closing this issue as I believe this is resolved in the latest versions.

Источник

Error: cannot find module [Node npm Error Solved]

If you’re a developer that works with Node JS and JavaScript libraries and frameworks like React, Vue, and Angular, then you might have encountered the «Error: cannot find module» error.

In this article, I’m going to show you how to fix the error.

Why the «Error: cannot find module» Occurs

This error occurs because of the following reasons:

  • you’re trying to import an item from a module you don’t have installed in your project directory
  • you’re importing some things from an outdated package
  • you’re pointing to a file that does not exist

In the screenshot below, you can see that I’m getting the error:

ss1

I’m getting the error because I’m trying to import the freeCodeCamp icon from the react-icons package, which I don’t have installed.

import { FaFreeCodeCamp } from "react-icons/fa";

How to Fix the «cannot find module» Error

If you get this error, the solution is always in the error. The module (package) not found is always specified in the format «Module not found: Error: Can’t resolve ‘package name’ in ‘project directory».

In my case, I got it like this «Module not found: Error: Can’t resolve ‘react-icons/fa’ in ‘C:UsersuserDesktopProjectsAddress Locatoraddress-locatorsrc'».

To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn add package-name.

In my case, I need to install the react-icons package so the freeCodeCamp icon can be resolved. I’ll do that by running yarn add react-icons.

Once I install the package and run the app, everything should successfully compile:

ss2

If you install the package but you still get the error, then follow the steps below:

  • delete the node modules folder by running rm -rf node_modules
  • delete package.lock.json file by running rm -f package-lock.json
  • clean up the NPM cache by running npm cache clean --force
  • install all packages again by running npm install

That should fix the error for you.

Conclusion

When you get the “cannot find module” error, or “module not found”, it means you’ve not installed the package you’re trying to use.

If the error occurs even if you have the package installed, then the fixes suggested in this article can help you out.

Thank you for reading.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

JavaScript’s Node.js server supports module export and import in both ECMAScript modules and CommonJS format.

Sometimes, npm will throw an error saying Cannot find module because of module import as shown below:

$ node index.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'axios'
Require stack:
- /n-app/index.js
    at ... {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/n-app/index.js' ]
}

Here’s the content of the index.js file:

var axios = require("axios");

The cannot find module error occurs because npm cannot find the module required by the index.js file. In this case, the axios module.

To resolve the error, you need to make sure that axios is installed in the node_modules/ folder.

Please note that the node_modules/ folder must be located in the same directory as the index.js file:

.
├── index.js
├── node_modules
├── package-lock.json
└── package.json

If you have run the npm install command before, then it’s possible that the installation of the module is incomplete or corrupted.

Delete the node_modules/ folder using the rm -rf node_modules command, then run npm install again. That may fix the issue.

Finally, the same error can happen when you require() a local .js file that can’t be found.

Suppose you have a file named lib.js placed in the same folder as the index.js file:

.
├── index.js
└── lib.js

To import the file, you need to specify the correct path in the require() function.

The following code:

var helper = require("lib.js");

Will produce the same error:

$ node index.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'lib.js'
Require stack:
- /n-app/index.js
    at ... {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/n-app/index.js' ]
}

This is because the require() function will always look inside the node_modules/ folder.

To let Node.js knows that you are importing a local file, use the absolute path as follows:

The ./ syntax means the root directory where you run the node command. In this case, the folder where index.js is located.

If you have a file one level down like this:

.
├── index.js
└── helpers
    └── lib.js

Then you need to adjust the require() path as shown below:

var helper = require("./helpers/lib.js");

The same also applies when you use the ES modules format as follows:

import helper from "./helpers/lib.mjs";

To conclude, the error “Cannot find module” happens when Node.js can’t find the module that a file is trying to import.

You can see the file and the module that’s causing the issue from the error output generated by Node itself.

And that’s how you resolve the npm cannot find module issue. Great work! 😉

I am getting the following error whenever I try to run npm command.

internal/modules/cjs/loader.js:626
throw err;
^

Error: Cannot find module 'semver'
Require stack:
- /usr/share/npm/lib/utils/unsupported.js
- /usr/share/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/usr/share/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:681:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/share/npm/lib/utils/unsupported.js',
    '/usr/share/npm/bin/npm-cli.js'
  ]
}

I was basically trying to make offline use of FreeCodeCamp. It asked me to run command ‘npm ci’ from which I started getting this error.

I tried reinstalling npm but it won’t work. I also tried installing the semver module which also didn’t help.

What might have gone wrong and how can I fix this?

asked Jun 20, 2019 at 11:19

Shirish Pokhrel's user avatar

Shirish PokhrelShirish Pokhrel

3711 gold badge3 silver badges5 bronze badges

Found a similar question here and the answer worked.

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*

sudo apt-get purge nodejs npm
sudo apt autoremove

Download the latest tar.xz NodeJS file from https://nodejs.org/en/download/

tar -xf node-v#.#.#-linux-x64.tar.xz
sudo mv node-v#.#.#-linux-x64/bin/* /usr/local/bin/
sudo mv node-v#.#.#-linux-x64/lib/node_modules/ /usr/local/lib/

Where #.#.# is the version you downloaded.

Verify installation using

node -v
npm -v

answered Sep 3, 2019 at 0:01

Bilbo Baggins's user avatar

3

It depends on how you want to manage Node JS/npm.

As Bilbo Baggins suggested, you can install the latest LTS version of Node JS from the official website: https://nodejs.org/en/download/.

On Ubuntu, if you would rather manage Node through the default repositories using apt, it’s best to install both nodejs and npm this way.

It’s very likely that the version of npm you are using is expecting semver in a specific place that is not aligned with the version of Node JS you have installed. If there is only one version of nodejs and only one version of npm, and they are both installed using the default repositories, this should work perfectly.

Here is my best guidance for getting Node and npm working using the main Ubuntu repositories:

  1. sudo apt-get purge nodejs --auto-remove and sudo apt-get purge npm --auto-remove
  2. whereis node: remove all the versions of node, one at a time. Repeat until this command returns a blank after node:.
  3. sudo apt-get install nodejs
  4. node --version: should return ... no such file or directory
  5. nodejs --version: should return v1x.x.x. This is the version installed by apt. It will probably be less recent that the latest version available on the Node JS website.
  6. sudo apt-get install npm
  7. npm --version: it will use the nodejs installed by apt and work correctly.

answered Aug 28, 2020 at 14:23

Schmudde's user avatar

SchmuddeSchmudde

1711 silver badge4 bronze badges

I was using nvm to manage node versions, In my case npm syslink was broken i solved it by uninstalling and then reinstalling node again

check your node version using node --version

then run nvm uninstall <your version>

then reinstall using nvm install <your version

answered Aug 31, 2021 at 5:33

mumboFromAvnotaklu's user avatar

Run this command it will automatically remove previous version of npm and install new version of npm, worked for me, you can check here for details https://github.com/npm/cli

 curl -qL https://www.npmjs.com/install.sh | sh

answered May 20, 2021 at 8:55

Ujjawal Mandhani's user avatar

2

I was facing an Angular project. Somehow, Angular-CLI (ng) was removed.
So I just verified that node and npm are installed and did the following which fixed it:

sudo npm install -g @angular/cli 

ThunderBird's user avatar

ThunderBird

1,90513 gold badges19 silver badges31 bronze badges

answered May 5, 2021 at 5:37

Vikram Ray's user avatar

In my case I was using nvm so I had to remove all node versions (rm -rf ~/.nvm/versions/node/*)
then install both nodejs and npm :

sudo apt install nodejs
sudo apt install npm

answered Mar 20, 2022 at 11:19

Badr Bellaj's user avatar

I had the same issue but on 22.04. None of the above worked for me, but I found this process that did. https://codemarvels.com/2021/03/20/npm-install-gives-error-cannot-find-module-semver/
Essentially:

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*
sudo apt-get purge nodejs npm
sudo apt autoremove
sudo apt-get install nodejs npm

answered Aug 25, 2022 at 16:44

Andy Carr's user avatar

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

How to solve the Module Not Found error

brew uninstall --ignore-dependencies node
sudo chown -R $(whoami) /usr/local/*
brew cleanup
brew install node

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

When you are working in Node, you will sometimes encounter the error Cannot find module 'module-name' with the error code MODULE_NOT_FOUND.

The error looks like this:

	internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module 'module'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
        code: 'MODULE_NOT_FOUND',
        requireStack: []
    }

In this post, we’ll learn how to resolve this error.

What is the problem?

The issue is that Node is unable to find the module that you are trying to import into your Node application.

The most common reason for this is that you simply haven’t installed the project’s dependencies yet.

The project’s dependencies are listed in the package.json file at the root of the project.

The Solution

To fix the Cannot find module error, simply install the missing modules using npm.

To so, you can use the following command:

	npm install

If you are using the yarn package manager, you can use the following command:

	yarn install

This will install the project’s dependencies into your project so that you can use them.

Sometimes, this might still not resolve it for you. In this case, you’ll want to just delete your node_modules folder and lock file (package-lock.json or yarn.lock) and try again.

This is how you can delete the node_modules folder and lock files:

	rm -rf node_modules

rm package-lock.json
rm yarn.lock

Local files

If your module is not coming from a remote source, you are seeing the error because the path to the local file is not correct.

Try to confirm that the path pointing to the local module is correct and your error should be resolved.

Conclusion

The Cannot find module error is a common error that usually happens when dependencies are not installed. Once you install your dependencies and ensure that the paths are correct, you can resolve the error and run your application successfully.

Hopefully, this resolved the issue for you.

Thanks for reading!

If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!

  • Support Us

  • Join

  • Share

  • Tweet

  • Share

Give feedback on this page!

Понравилась статья? Поделить с друзьями:
  • Error cannot find module inherits
  • Error cannot find module mysql
  • Error cannot find module mongoose
  • Error cannot find module minimist
  • Error cannot find module lodash