coreybutler / nvm-windows

A node.js version management utility for Windows. Ironically written in Go.
MIT License
37.84k stars 3.34k forks source link

NPM not installed with node #199

Closed NealHumphrey closed 6 years ago

NealHumphrey commented 8 years ago

My Environment

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!

coreybutler commented 8 years ago

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.

NealHumphrey commented 8 years ago

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 \nodejs\node_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

coreybutler commented 8 years ago

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%.

NealHumphrey commented 8 years ago

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!

LeeGDavis commented 8 years ago

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.

NealHumphrey commented 8 years ago

@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?

coreybutler commented 8 years ago

@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).

frankorama commented 8 years ago

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.

LeeGDavis commented 8 years ago

@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...

felipe-gdr commented 8 years ago

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

coreybutler commented 8 years ago

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.

LeeGDavis commented 8 years ago

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.

coreybutler commented 8 years ago

@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.

coreybutler commented 8 years ago

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.

d-mg commented 8 years ago

@coreybutler @LeeGDavis Windows Defender was the culprit for me

se-m commented 8 years ago

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."

coreybutler commented 8 years ago

@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.

se-m commented 8 years ago

@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)
coreybutler commented 8 years ago

@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.

espoelstra commented 8 years ago

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.

weedgrease commented 7 years ago

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

hielfx commented 7 years ago

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

wittibs commented 7 years ago

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.

yuxblank commented 7 years ago

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.

manolkalinov commented 7 years ago

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

SamFarrington commented 7 years ago

@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?

hutber commented 6 years ago

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

kosmjon commented 6 years ago

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

js2me commented 6 years ago

+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

mjasnikovs commented 6 years ago

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

carlosquijano commented 6 years ago

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

AndreaCole1340 commented 6 years ago

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\nodejs\node_modules\npm\lib\utils\error-handler.js:205:18)

using windows 10 node version 8.9.4

jokam85 commented 6 years ago

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

js2me commented 6 years ago

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

alaindeurveilher commented 6 years ago

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:

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.

nickpainter commented 6 years ago

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

jokam85 commented 6 years ago

the latest version of nvm resolved issue for me.

dmidz commented 6 years ago

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 !

acroyear commented 6 years ago

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.

YafimK commented 6 years ago

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.

malcoriel commented 6 years ago

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:\ProgramData\nvm\v10.7.0\node_modules\npm. 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:\ProgramData\nvm\v10.7.0\node_modules\npm. 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.

bryandrenner commented 6 years ago

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.

coreybutler commented 6 years ago

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.

robertmain commented 6 years ago

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

Thanks for fixing though.

ralfhandl commented 6 years ago

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.

mmascolino commented 6 years ago

Same situation as ralfhandl here.

coreybutler commented 6 years ago

@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).

coreybutler commented 6 years ago

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.

mmascolino commented 6 years ago

Definitely did a nvm use 8.11.4 before trying to use npm

coreybutler commented 6 years ago

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.