Nvm-windows: NPM not installed with node

Created on 15 Aug 2016  ·  66Comments  ·  Source: coreybutler/nvm-windows

My Environment

  • [ ] Windows 7 or below (not truly supported due to EOL - see wiki for details)
  • [ ] Windows 8
  • [ ] Windows 8.1
  • [x] Windows 10
  • [ ] Windows 10 IoT Core
  • [ ] Windows Server 2012
  • [ ] Windows Server 2012 R2
  • [ ] Windows Server 2016
  • [ ] My Windows installation is non-English.

    I have already...

  • [x] read the README to be aware of npm gotchas & antivirus issues.

  • [x] reviewed the wiki to make sure my issue hasn't already been resolved.
  • [x] verified I'm using an account with administrative privileges.
  • [x] searched the issues (open and closed) to make sure this isn't a duplicate.
  • [x] made sure this isn't a question about how to use NVM for Windows, since gitter is used for questions and comments.

    My issue is related to (check only those which apply):

  • [ ] settings.txt

  • [ ] proxy support
  • [ ] 32 or 64 bit support

    Expected Behavior

After installing nvm-windows using the installer and then installing a version of node using >nvm install latest or >npm install 4.4.7. I expect to be able to type >npm help into the command line to verify npm is working (and then of course use it to install packages).

Actual Behavior

While nvm says that npm was installed, the folders containing node_modules are blank:
...\AppData\Roaming\nvm\v4.4.7\node_modules (empty)
C:\Program Files\nodejs\node_modules (empty)

Steps to reproduce the problem:

First I installed nvm 1.1.1 from here: https://github.com/coreybutler/nvm-windows/releases

I installed node version 4.4.7 using nvm install 4.4.7. All nvm commands work correctly including nvm use and I can run a hello world script in node.

During installation, I get the following command line output:

>nvm install 4.4.7
Downloading node.js version 4.4.7 (64-bit)... Complete
Creating C:\Users\myusernamewithoutspaces\AppData\Roaming\nvm\temp

Downloading npm version 2.15.8... Complete
Installing npm v2.15.8...

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

nvm use 4.4.7

When I then type npm help into the command line I get this error:

module.js:327
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3
 module.js:327
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

Thanks for any help!

Most helpful comment

Had this same issue. What fixed it for me: removing "C:\Users\{your_username}\AppData\Roaming\npm" from my PATH variable. I think it was leftovers from a previous node install.

All 66 comments

UPDATE
In reviewing the original post, I noticed this block:

>nvm install 4.4.7
Downloading node.js version 4.4.7 (64-bit)... Complete
Creating C:\Users\myusernamewithoutspaces\AppData\Roaming\nvm\temp

Downloading npm version 2.15.8... Complete
Installing npm v2.15.8...

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

nvm use 4.4.7

Notice the nvm use 4.4.7 is part of the _instructions_ that NVM4W outputs after a new Node installation completes. If you _don't actually run_ nvm use x.x.x, then node isn't recognized, and therefore npm isn't recognized. Make sure you run nvm use x.x.x (where x.x.x is the version you want to run) before trying to run any npm commands!

Original Response
Are you behind a proxy? This issue has come up for some users before... mostly those using proxies.

I would check to make sure the C:\Program Files\nodejs\node_modules\npm\bin exists when using a specific version.

It might be worth trying to uninstall/reinstall the version you want. At the end of the day, NVM4W just hands control off to node/npm once the files are downloaded/extracted. The challenge is, sometimes the download can show a false positive (i.e. didn't complete the npm download but says it did). I suspect this might be what's happening for you.

Thanks @coreybutler. I'm not behind a proxy, but there is a basic firewall. I tried a fresh install of NVM4W and nvm install 4.4.7 with the firewall turned off. Result is the same - both the \AppData node_modules is completely empty and the \nodejsnode_modules folder is empty.

Any other ideas? I'll also check the node install docs about issues with installing npm if it's handing off control

I don't think you need to install NVM4W with the firewall off (since it was responding)... but you might want to test running nvm install x.x.x with the firewall off. I still suspect the npm download may not be completing 100%.

yep, I did do the install with firewall off and it didn't help. I'm not sure how to test what else may be going wrong with the download or otherwise. If you have any other ideas let me know!

I'm experiencing this same issue using nvm 1.1.1 and windows 10. Is there any information you need to help debug. This one is really weird to me. It will work for a while then eventually stops working and can no longer find npm.

@NealHumphrey if you uninstall the version you are using then delete the install folder for that version in your nvm root, then reinstall, this usually works for a couple weeks for me then it will stop working again with the same error you have reported.

@LeeGDavis - I haven't ever been able to get it to work, even reinstalling the Node version or reinstalling NVM4W and then Node.

For debugging - when you are able to get it to work, what are the contents of these two folders?
...\AppData\Roaming\nvm\v4.4.7\node_modules
C:\Program Files\nodejs\node_modules

And then next time it stops working for you, can you check again on what the contents are?

@LeeGDavis - If it just stops working after a period of time, there is definitely something going on in your environment. NVM4W doesn't touch anything, ever, unless you run an nvm command. Somewhere, something is being modified. It would help to know more about the environment. For example, are you on an Active Directory domain? Do you have any scheduled tasks? Do you have antivirus installed, and if so, which one(s)?

@NealHumphrey - Just to clarify, you are running nvm install to install node with the firewall off, as opposed to running the whole nvm installation (GUI) with the firewall off? If you want to check the downloads, you can compare the checksum of the versions (available on nodejs.org).

Having the same issue. Turned off my McAfee firewall and the installation seems to have worked this time: the \node_modules\nvm folder is there.

Tested the installation by switching to my newly installed version of Node (6.2.2) and executing the npm --version command and it returned 3.9.5

UPDATE: had to uninstall because reasons. When I reinstalled (firewall still off), the problem reappeared: the \node_modules\nvm\ folder is missing. I tried using the GIT BASH terminal and the command prompt in administrator mode to install Node, but always the same result.

UPDATE 2: Turned off the firewall and virus scanner and it worked again, using the command prompt in administrator mode.

@NealHumphrey and @coreybutler The problem happened again under a week, so I switched to vanilla node, but will switch back to nvm this week-end to help debug.

I am not on any domain controlled/active directory setup and no scheduled tasks. In regards to install, nvm never reports a failure, but removing the install folder in the nvm root is needed to get it working again once the executable gets nuked from the path or whatever is happening...

Had this exact same problem. Uninstalled MVN, turned off Mcafee real time protection and firewall, reinstalled it, and the error vanished.

Definitely an antivirus issue. However; it sounds like it might be something that could be modified in the settings. I verified this morning that NVM4W is whitelisted by Mcafee.

The windows box I am using is vanilla windows 10 pro installation. No other third party antivirus or firewall installed, besides the default Windows defender and firewall I suppose. What is odd for me a particular version (of node installed through nvm4w) will work for a time before it appears to just stop working and the only way to restore it appears to be what I described above.

@LeeGDavis Windows Defender can remove files as well. However; NVM4W is whitelisted there too. I recommend reviewing your %PATH% the next time this happens. I'm starting to suspect that in your case, perhaps the AV is modifying the path. In other words, everything may be right, but Windows can't find it. If this keeps happening, open a new issue so we can track it.

As for not getting npm installed, I still think it's just the firewall/antivirus blocking the download of npm from the node distribution site. If @frankorama's solution works, this is the case and there's not much that can be done within NVM4W to prevent that. I can try adding exceptions to the firewall in the installer at some point, but that doesn't mean they wouldn't get overwritten by 3rd party software.

@coreybutler @LeeGDavis Windows Defender was the culprit for me

I had this issue. (windows 7x64, nvm v1.1.1)
After some digging around , I found, that it seems problem is in os.Rename(tempDir+"\\nvm-npm\\npm-"+npmv,env.root+"\\v"+version+"\\node_modules\\npm"), because all previous steps were done correct.
I can propose, that when this command is executed dir is still busy due to previous rename commands.
Maybe reorder commands to something like

os.Rename(tempDir+"\\nvm-npm\\npm-"+npmv,env.root+"\\v"+version+"\\node_modules\\npm")
os.Rename(env.root+"\\v"+version+"\\node_modules\\npm\\bin\\npm",env.root+"\\v"+version+"\\npm")
os.Rename(env.root+"\\v"+version+"\\node_modules\\npm\\bin\\npm.cmd",env.root+"\\v"+version+"\\npm.cmd")

or catch an error and try again (after 1 sec sleep)

UPD
I typed the last result of renaming ang got
"rename .... Access is denied."

@se-m Thanks for the insight. The order is important, but it seems like there's a synchronicity problem.... at least in your environment. Which version of Go are you running your tests with?

If file movement is indeed the problem, I don't like using sleepers because it doesn't really solve the problem. os.Rename _should_ just move the files, but it appears that may not be reliable.

@coreybutler i used go1.7 for my test (just print the error)
I do not see the difference between the "first move the files from the folder and then the folder" and the "first move the folder and then move the files out of it" (paths were corrected in the example).

If you will not use the sleepers or reorder, I can only suggest using a "copy" comand instead of "move".

To all.
Check that you have it "synchronicity problem" (after nvm install x.x.x):

  1. There are 2 files "npm.cmd" and "npm" in the newly installed node folder (vx.x.x)
  2. There is no folder "npm" inside node_modules (vx.x.x/node_modules)

@se-m Yeah, the plan would be to use a copy. This way a checksum can be matched with the download, then again once the copy is complete. Logging can be applied to both steps, checking for file integrity and permissions.

Rather than use either sleepers or an extra copy I'd just catch the known exception and retry, this way you won't have a race condition and you can retry X times before giving up to cope with slow "spinning rust" disks or the case of someone installing to a network synced roaming profile.

I know this is a bit old, but can confirm that disabling McAfee while installing worked.

Also I had to disable 360 TS to get it working, thanks

Had this same issue. What fixed it for me: removing "C:\Users\{your_username}\AppData\Roaming\npm" from my PATH variable. I think it was leftovers from a previous node install.

I have the same problem @office where we have mcAfee enterprise, when it works fine on my home pc.
I solve this way (it's the faster one), i download NPM packages and i copy the content to the node_modules/npm folder. It works fine.

@yuxblank I am in the same boat as you - McAfee Enterprise at the office. Disabling it is not an option. Your solution helped me.

@yuxblank @manolkalinov

I've tried the suggested method and whilst it does get npm working, global installs still do not work for me - with the same behaviour as npm, the node_modules just being empty other than what I have manually copied in.

Was this the same for you guys also?

I've a fresh install of Windows 10 Pro with no previous installed npm or node and currently I have node installed via nvm install latest but no npm

Same issue Windows 10 pro while installing 8.9.1. Got node, but nvm\v8.9.1node_modules is empty as is c:\program files\nodejsnode_modules. Work computer has McAffee that cannot be disabled. I will download npm and manually install.

+1
before it install fresh node version (9.5.0)
after it install nvm and was try to switch to 6.10.0 version and it switched but if
I run npm start then I saw:

module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

If I switched back to installed 9.5.0 node version(installed not using nvm) then npm start works

Windows 10 fresh install, no antivirus, no npm... :(

same here, turned off Mcafee both real time protection and firewall, reinstalled it and npm is now available.

turnt off McAfee firewall and real time protection did a fresh install and got a Error : EISDIR illegal operation on a directory, read.
TYPE ERROR: Cannot Read property 'get' undefined at errorHandler (C:\Program Files\nodejsnode_modulesnpm\lib\utilserror-handler.js:205:18)

using windows 10
node version 8.9.4

Avira antivirus caused this problem on my pc. Win10, any node and npm

I reinstall operation system from Windows 10 to 7 and use NVM without any problems 😁

I had the same problem, and I found totally by chance a possible workaround (but not verified as I didn't want to uninstall my new version of node again). So here what happened:

  • once nvm install is running, a temp folder is created in AppData/Roaming/nvm/
  • when it's created I went into the temp folder -> nvm-npm -> npm-x.y.z with an explorer (or maybe in nvm-npm I don't remember well)
  • I think that somehow by exploring that folder, it kinda locks it, and prevents Windows from deleting it
  • And then I observed that that time the npm folder was correctly moved to the nvm/vx.y.y/node_modules, while it always failed before.

So according to these observation, my guess is that, maybe, during the installation, the temp folder is deleting faster than the move command from temp to the target node folder, leaving to move command with no files to move.

I encountered this issue, but was able to resolve it by simply re-running the nvm use command.

the latest version of nvm resolved issue for me.

After many tries, only disabling the McAfee "Access Protection" let nvm finally install npm correctly !
What is really disturbing is McAfee do not show any log for that : "No any threat" my lord...yeah just prevented few files to be created, I would say it is a event !

Unfortunately for me, nothing of the above is working. McAfee is disabled, defender is off, but i still get the problem. As AlainD noted, I AM seeing it download and stage in temp...but if i try to do what he suggests, I end up in an empty folder. Nothing is copied to node_modules AND the folder I am in is empty - the trail of folders down to where i was is all that remains.

So yeah, the problem is definitely the move/copy from temp to node_modules that has the problem.

Yes I've tried running as administrator cmd as well as regular. I haven't put git bash on this box yet.

resolved by copying the npm folder (under nodemodules) from the zip archive I've manually downloaded from nodejs.org. Not perfect but solved the McAfee issue.

I also had the same problem, but mine was rather incomplete npm install after switching to node 10.7.0 and npm 6.1.0 - it first lacked uuid package, then semver package in C:\ProgramDatanvm\v10.7.0node_modulesnpm. I don't have McAfee, though I do have COMODO anti-virus.

My solution was almost the same as YafimK's - but I just copied the npm-v6.1.0.zip from nvm\temp folder, and then manually unpacked it into C:\ProgramDatanvm\v10.7.0node_modulesnpm. Judging from its contents, you can simply download the same folder from https://github.com/npm/cli/releases without meddling with temp folders.

Hope this helps somebody. I also hope nvmw resolves this issue.

This seems to be an intermittent issue.

nvm uninstall 9.4
rm -r ~\AppData\Roaming\nvm\v9.4.0
nvm install 9.4
nvm use 9.4
Start-Sleep -Seconds 1
npm --version

If I run this script repeatedly from PowerShell as an administrator, sometimes it sometimes succeeds installing npm, and sometimes it fails with the error, Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'.

So basically, I'm able to get it working just by uninstalling and reinstalling until it randomly works.

npm changed their repo from npm/npm to npm/cli. It would have affected any install of Node 10.8.0+. This has been fixed in 1.1.7.

@coreybutler Well that's mildly infuriating to say the least :/

Thanks for fixing though.

Just installed nvm 1.1.7 and still have this issue on Windows 10 Enterprise 1709.
Disabling McAfee Endpoint Security Firewall before installing nvm and using nvm install did not help.

Same situation as ralfhandl here.

@robertmain - indeed. npm has changed things several times without so much as a peep.

@ralfhandl & @mmascolino - just making sure... you ran nvm use x.x.x before npm help, right? I looked over the original issue and realized the OP didn't actually mention running that (though the comment shows the output of nvm with instructions for running nvm use).

I'm closing this issue for the following reasons:

  1. Several people forgot to run nvm use x.x.x (see my updated response to the original message above)
  2. The npm repo change was accounted for (see issue #373)
  3. There's not much I can do about some versions of npm where permissions are hard-coded. See https://github.com/coreybutler/nvm-windows/issues/300#issuecomment-332030011 for detail.

If you're still experience an issue like this, open a new issue.

Definitely did a nvm use 8.11.4 before trying to use npm

Node 8.x.x is subject to npm's hard-coded permissions (see #300). Can someone with Win 10 Enterprise (@mmascolino or @ralfhandl) try with a newer or older version of Node? I see no reason why NVM4W would behave differently in that flavor of Windows, but there is the known npm issue in Node 8.x.x that could be the culprit.

I've installed Node versions 10.9.0, 8.11.4, 6.14.4, and 6.9.0.

In all cases nvm install x.y.z appeared to work fine, and after nvm use x.y.z Node itself worked fine, but npm was missing and I had to separately download npm and unzip it into C:\Users\xxx\AppData\Roaming\nvm\vx.y.z\node_modules.

here you go:

C:\Users\mascolino.mm>nvm install 10.9.0
Downloading node.js version 10.9.0 (64-bit)...
Complete
Creating C:\Users\mascolino.mm\AppData\Roaming\nvm\temp

Downloading npm version 6.2.0... Complete
Installing npm v6.2.0...

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

nvm use 10.9.0

C:\Users\mascolino.mm>nvm use 10.9.0
Now using node v10.9.0 (64-bit)

C:\Users\mascolino.mm>npm
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

The node_modules folder (C:\Users\mascolino.mm\AppData\Roaming\nvm\v10.9.0\node_modules) is completely empty.

Same as @mmascolino here

Same as @mmascolino here, the only difference on me is the destination folder for node versions which is c:\ProgramDatanvm\v10.11.0.

The node_modules folder is completely empty.

same

I'm also having the same issue.

Make sure you've removed prior installations of Node (as instructed in the README). This is the most common reason for these errors, because npm is getting confused between versions. Notice the error states Cannot find module, which is an npm error. This indicates npm _is_ detected.... but not the right version.

Also check your temp directory, in @mmascolino's case it would be C:\Users\mascolino.mm\AppData\Roaming\nvm\temp to see if there are files. If nothing is there, the download may have failed for some reason... which could be a firewall setting, network glitch, or permissions issue.

@coreybutler IMO, the README needs to be improved. If this is an required step, it should be its own paragraph and bolded.

This is the current copy:

It comes with an installer (and uninstaller), because getting it should be easy. Please note, you need to uninstall any existing versions of node.js before installing NVM for Windows. Also delete any existing nodejs installation directories (e.g., "C:\Program Files\nodejs") that might remain. NVM's generated symlink will not overwrite an existing (even empty) installation directory.

This doesn't highlight the importance of uninstalling existing versions, nor does it provide an easy way for users to do that. If this is a requirement for nvm-windows working, we should display a warning when ran (e..g C;\Program Files\nodejs exists, this may cause problems with installation). Better yet would be providing a command to clean existing installations.

@cdtinney - The installer has a note about this in it. I can't make it bold (in the installer), but there is a screen for it. Feel free to update the README and submit a PR. I'd accept it.

Hi,

I had a similar issue to the one reported here using nvm 1.1.7 on Windows 10 which has been resolved in the latest head of master.

Essentially, nvm was downloading nodejs, npm zip was correctly downloaded and extracted. The copy to the nodes_module directory failed however with no error.

I pulled the latest master version and built locally the install worked correctly.

One issue I did notice when debugging is that on line https://github.com/coreybutler/nvm-windows/blob/0a258f810d13eb20c56f6bebe575cd7451348d03/src/nvm.go#L298
If the move fails after the retries, the error is not logged or the install does not fail.

Would you be able to release a new version from the latest version of master?

Thanks for the work & kind regards,
Fergus

I just had this issue. I have tried all solutions except disabling McAfee, which I'm not allowed to do so the only solution that worked for me is to download node's Windows Binary zip file, unzip it, and move the npm folder located in its node_module and place it in the one created by nvm-windows located in C:\Program Files\nodejsnode_modules

My env is Windows 10 64bit 1803, using latest nvm windows 1.1.7.

Some people needs to edit npm.cmd and add the PATH. (somewhere below nvm directory, probably nvm\vX.Y.Znpm.cmd)

At line 6, node executable file is specified.
In my env, it indicated below.
SET "NODE_EXE=%~dp0\node.exe"

This tries to use node.exe in the same directory.
But actually there is node64.exe, instead of node.exe.
So I rewrite node.exe to node64.exe.

After that, you need to add the directory where npm.cmd exists to PATH.
Close all cmd.
This works fine since opening new cmd.

I don't know this also works fine if you use and switch multiple nodejs versions.

Can confirm McAfee breaks npm. We already excluded a specific folder, just install nvm and npm paths into that folder.

I had this issue too.
I solved this issue by running nvm-setup.exe as an administrator

Change the installation directory to C:\ NVM 🎉

I'm locking this conversation because new issues should be filed as.... new issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SufyanParkar picture SufyanParkar  ·  4Comments

keylowgee picture keylowgee  ·  6Comments

Deilan picture Deilan  ·  4Comments

eliavmaman picture eliavmaman  ·  6Comments

ctsstc picture ctsstc  ·  3Comments