Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM not installed with node #199

Closed
6 of 17 tasks
NealHumphrey opened this issue Aug 15, 2016 · 66 comments
Closed
6 of 17 tasks

NPM not installed with node #199

NealHumphrey opened this issue Aug 15, 2016 · 66 comments

Comments

@NealHumphrey
Copy link

NealHumphrey commented Aug 15, 2016

My Environment

  • Windows 7 or below (not truly supported due to EOL - see wiki for details)
  • Windows 8
  • Windows 8.1
  • 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...

  • read the README to be aware of npm gotchas & antivirus issues.
  • reviewed the wiki to make sure my issue hasn't already been resolved.
  • verified I'm using an account with administrative privileges.
  • searched the issues (open and closed) to make sure this isn't a duplicate.
  • 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!

@coreybutler
Copy link
Owner

coreybutler commented Aug 15, 2016

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
Copy link
Author

NealHumphrey commented Aug 15, 2016

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
Copy link
Owner

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
Copy link
Author

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
Copy link

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
Copy link
Author

@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
Copy link
Owner

@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
Copy link

frankorama commented Aug 24, 2016

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
Copy link

@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
Copy link

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

@coreybutler
Copy link
Owner

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
Copy link

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
Copy link
Owner

@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
Copy link
Owner

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
Copy link

d-mg commented Aug 28, 2016

@coreybutler @LeeGDavis Windows Defender was the culprit for me

@se-m
Copy link

se-m commented Aug 30, 2016

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
Copy link
Owner

@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
Copy link

se-m commented Aug 31, 2016

@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
Copy link
Owner

@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
Copy link

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
Copy link

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

@hielfx
Copy link

hielfx commented Mar 1, 2017

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

@wittibs
Copy link

wittibs commented Mar 29, 2017

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
Copy link

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
Copy link

@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
Copy link

@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
Copy link

hutber commented Jan 10, 2018

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
Copy link

kosmjon commented Jan 25, 2018

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
Copy link

js2me commented Feb 7, 2018

+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

@acroyear
Copy link

acroyear commented Jul 7, 2018

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
Copy link

YafimK commented Jul 22, 2018

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
Copy link

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
Copy link

bryandrenner commented Jul 31, 2018

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
Copy link
Owner

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
Copy link

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

Thanks for fixing though.

@ralfhandl
Copy link

ralfhandl commented Aug 19, 2018

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
Copy link

Same situation as ralfhandl here.

@coreybutler
Copy link
Owner

@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
Copy link
Owner

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 NPM github repo is moving from npm/npm to npm/cli and it causes NVM to fail to install it #373)
  3. There's not much I can do about some versions of npm where permissions are hard-coded. See Cannot update npm (node 8.4.0) #300 (comment) for detail.

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

@mmascolino
Copy link

Definitely did a nvm use 8.11.4 before trying to use npm

@coreybutler
Copy link
Owner

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.

@ralfhandl
Copy link

ralfhandl commented Sep 5, 2018

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.

@mmascolino
Copy link

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.

@3nigm4
Copy link

3nigm4 commented Sep 26, 2018

Same as @mmascolino here

@hoghweed
Copy link

hoghweed commented Oct 5, 2018

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

The node_modules folder is completely empty.

@shavyg2
Copy link

shavyg2 commented Oct 9, 2018

same

@cdtinney
Copy link

I'm also having the same issue.

@coreybutler
Copy link
Owner

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.

@cdtinney
Copy link

cdtinney commented Oct 29, 2018

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

@coreybutler
Copy link
Owner

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

@fbyrne
Copy link

fbyrne commented Nov 16, 2018

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


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

@kenmarshall
Copy link

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

@anonymoussoh
Copy link

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.Z\npm.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.

@ElanHasson
Copy link

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

@Denon
Copy link

Denon commented Jan 15, 2019

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

@Lizhilin
Copy link

Change the installation directory to C:\ NVM 🎉

@coreybutler
Copy link
Owner

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

Repository owner locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests