Nvm-windows: Clean install of nvm 1.1.5, node 8.10.0 - npm not working

Created on 25 Jun 2018  路  27Comments  路  Source: coreybutler/nvm-windows

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

Downloading npm version 5.6.0... Complete
Installing npm v5.6.0...

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

nvm use 8.10.0

C:\Users\me> nvm use 8.10.0
Now using node v8.10.0 (64-bit)

C:\Users\me> npm --version
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

The directory C:\Users\me\AppData\Roaming\nvm\v8.10.0\node_modules exists, but is empty.

Most helpful comment

Still having the same problem.
Still haven't seen 1.1.8 after one year @coreybutler

All 27 comments

I have the exact same issue.

Check that your user name does not have space, in some cases "C:\Users\Name LastName\AppData\Roaming\nvm", when I changed the nvm installation folder to another location "C:\node\nvm" , the installation of node + npm worked fine.

There are no spaces (or other odd characters) in nvm root.

I have the exact same issue also with nvm 1.1.6 and installing node 10.6.0 (or any other node version).

If I navigate to <nvm-root>/v10.6.0/node_modules the folder is just empty. This fits to the error message when trying to run npm.

 Directory of C:\Users\flawi\AppData\Roaming\nvm\v10.6.0\node_modules

09.07.2018  18:22    <DIR>          .
09.07.2018  18:22    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  220.739.076.096 bytes free

If I observe the installation process after nvm install 10.6.0, I can see how npm is downloaded and extracted in C:\Users\flawi\AppData\Roaming\nvm\temp (I see the npm-v6.1.0.zip and the extracted folders). However, after the installation nothing is moved to <nvm-root>/v10.6.0/node_modules.

For completeness here is my settings.txt:

root: C:\Users\flawi\AppData\Roaming\nvm
path: C:\Program Files\nodejs

By the way, I have same issue also with nvm versions 1.1.5 and 1.1.4 (also if I use paths without spaces).

Mitigation

If you copy npm-v6.1.0.zip from <nvm-root>/v10.6.0/temp after the download is complete and extract it yourself into <nvm-root>/v10.6.0/node_modules/npm everything is working fine.

I saw this to trying to install node 10.6.0 with 1.1.5. I even ran in an admin command prompt from the get-go.

If I downloaded the 10.6.0 package from the nodejs.org website and compared it to what was in the nvm/v10.6.0 directory, what nvm installed was missing over half the npm packages.

After copying, everything worked fine, but nvm gave no indication that the install hadn't completed successfully.

353 related?

I have the same issue. Installed 10.7.0, npm does not work. No spaces in nvm root

To clarify, I had a node_modules folder and an npm folder in it, but it was missing files and was given no errors in any of my attempts to install or reinstall. Once I deleted that npm folder, downloaded npm-v6.1.0.zip manually and extracted my npm works fine.

Similar problem (with fresh install of nvm 1.1.5 - after uninstalling node and removing any npm directories in user\AppData...). When I type npm I get the following.

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

Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at C:\Users\timhu\AppData\Roaming\nvm\v10.7.0\node_modules\npm\bin\npm-cli.js:22:13
at Object. (C:\Users\timhu\AppData\Roaming\nvm\v10.7.0\node_modules\npm\bin\npm-cli.js:145:3)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
internal/modules/cjs/loader.js:583
throw err;
^

Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at C:\Users\timhu\AppData\Roaming\nvm\v10.7.0\node_modules\npm\bin\npm-cli.js:22:13
at Object. (C:\Users\timhu\AppData\Roaming\nvm\v10.7.0\node_modules\npm\bin\npm-cli.js:145:3)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

So, I was having a similar problem to this and resolved it. I'll relay the steps I took to resolve it, and hopefully it helps someone.
tldr;
try: nvm install <nodeversion> <32 or 64>
nvm install 8.11.4 64

First, I installed nvm, then node 8.11.4.
Did nvm use 8.11.4
When I tried npm, windows couldn't find it, and the node_modules folder in the 8.11.4 install was empty.
Uninstalled nvm.
Tried to install nodejs straight from nodejs.org and it gave me a long filepath error.
May not need to be done, but I did it...
Edited my system registry to allow long file paths for all users ->
In regedit go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Policies and set/create a DWORD (32-bit) entry called LongPathsEnabled with a value of 1. (There's a way to do this in Windows Pro without going into the registry, but I'm on Home, and that's not an option)


Installed nvm again, then nvm install 8.11.4.
Got some security error.
uninstalled 8.11.4
reinstalled SPECIFYING 64-bit with command nvm install 8.11.4 64

After that, everything seems to work.
Like I said, hopefully this helps someone else, but I'm sure mileage may vary. Good luck!

I'm having the same problem with nvm 1.1.7.

  • I have deleted all references to node/npm
  • Clean install nvm 1.1.7
  • nvm install 6.5.0
  • nvm use 6.5.0
  • npm install -g gulp
  • Creates a npm folder in my AppData\Roaming\ folder and puts gulp in \npm\node_modules
  • My AppData\Roaming\nvm\v6.5.0\node_modules only has npm folder in it

Am I missing some PATH parameters? I have %NVM_HOME% and %NVM_SYMLINK%

Further to this, it seems that even though gulp is installed into the main npm folder in Roaming, it is not being used. If I type the gulp command it can't find it, if I move the gulp files to the relevant nvm folder it works.

So it looks in the right place for its commands, just doesn't install it to the right place.

Ok I think I have found the problem. Looks like internally npm is still really holding on to the AppData\Roaming folder for its settings, one of which is the prefix. If you do npm config get prefix it will most likely point to the wrong location. You need to run npm config set prefix with the location of the special nodejs folder that nvm creates which is the %NVM_SYMLINK%. Now when I run all my npm installs it puts it in the right location, even if I switch nvm versions.

Source for fix (unrelated to nvm): https://stackoverflow.com/a/38270345/1535244

EDIT: The setting for prefix is in the .npmrc file in C:\Users\You\ folder. If for some reason that setting exists in there it will be used and it doesn't look like nvm changes it so it will always look at the wrong location. Removing this entry in this file also fixes the issue.

I'm not sure if this will help anyone, but I'll leave it here just in case. I also had this issue and I found what @dfibuch and @flawi said was pretty useful for finding understanding the issue that I was having. So here's all my info:

  • I don't have any spaces in my path
  • nvm version 1.1.6
  • Working with 64-bit executables
  • Using Git Bash in Windows
  • I did delete the setting for ; prefix=C:\Program Files\nodejs from my .npmrc and the value I was getting with npm config get prefix didn't change, it continues to be ~\AppData\Roaming\npm.

In my case, I was trying to install the latest node version (currently 10.9.0) because I needed my npm version to be >6 to be able to run npm audit, and the last node version I had installed was 8.11.3, which came with npm version 5.6.0.

Before deleting the prefix setting, when I installed node version 10.9.0 with nvm install latest 64 all I did get in my ~\AppData\Roaming\nvm folder was a new folder called v10.9.0 that only had node.exe in it, but no node_modules (it's like it wasn't even trying to install npm). After I deleted the prefix, I started to get the node_modules folder created inside nvm\v10.9.0, but I was still getting an error during installation:

$ nvm install latest 64
Downloading node.js version 10.9.0 (64-bit)...
Complete
Downloading npm version 6.2.0... Download failed. Rolling Back.
Rollback failed. remove ~\AppData\Roaming\nvm\temp\npm-v6.2.0.zip: The process cannot access the file because it is being used by another process.
Could not download npm for node v10.9.0.
Please visit https://github.com/npm/npm/releases/tag/v6.2.0 to download npm.
It should be extracted to ~\AppData\Roaming\nvm\v10.9.0

So deleting the prefix setting improved things a little bit for me, but did not solve the issue completely. I also closed everything and re-tried, so there's no way that "it is being used by another process".

After that, I decided to try @flawi's process. I did find the npm-v6.1.0.zip file in my nvm/temp folder and tried to extract npm into my nvm\v10.9.0 folder, and that threw the error that the zip file is corrupted or has incorrect format. That might be the reason why nvm can't move it or extract it into my latest installation of node.

Maybe the issue is not completely nvm, but also the latest version of npm inside node's v 10.9.0.

I got back to using v 8.11.3 and updated npm with npm install npm@latest -g. It got updated correctly and I'm able to run npm audit. So that's why I think it could be an issue with the package inside 10.9.0 but not the package itself.

I would also like to add that I had a similar problem like @dfibuch. I installed serve globally a week ago and it got installed in a different folder than ~\AppData\Roaming\npm\version\node_modules, and also did gulp. Gulp worked anyway (I'm not completely sure why) but in order to make the serve package work, I had to copy it manually from where it got installed into my version folder inside nvm.

Upgrade to v1.1.7, which resolves #373 (issues with npm for Node 10.x.x+). The issue with spaces in the path has been resolved in master (via PR #355) and is scheduled for release in 1.1.8. If you need the functionality right now, you can build from source. I'll get 1.1.8 out as soon as I can, but there are a few other fixes still being merged in.

Closing since the aforementioned issues/resolutions should resolve this one.

I had de same issue (empty node_modules dir) and disabling antivirus solved the problem (using nvm 1.1.7)

Same as @sergioedo (disabling the antivirus when installing via nvm). Thanks for the help!

Still having the same problem.
Still haven't seen 1.1.8 after one year @coreybutler

Going to two years now @coreybutler, nothing?

@filipemerker

(2019-09-06) I am actively working on new Github actions to build releases. There are several great contributions in master (which contains the to-be-released 1.1.8 version), but I've always had to build these by hand.... and as many of you have noticed, my time has been extremely limited for quite awhile. The time consuming part is preparing the NSIS build, but once that is automated, it should be significantly easier for people to contribute changes and actually see them released.

Of course I still don't think 1.1.8 will fix this (unless there have been other changes not mentioned here). There's something about the way it tries to install npm that anti-virus really doesn't like, and a blanket "disable AV" is not something that everyone wants to do or even can do.

For McAfee Endpoint Security, it is "On-Access Scan" that blocks it. However, there's never anything in its logs when it does (or they're only accessible to my network admins).

@tedyyu @filipemerker Github actions completely changed when I was working on it... different formats, libraries, etc. Kind of had to restart, then Go switched to modules. By that time, I was busy with other things (see this and this). Thus no new releases. It hasn't fallen of my radar... in fact, we're working on a whole new CLI dev environment, since NVM4W is just one of many.

A _very_ early draft mockup:

image

RE: Antivirus & npm

The major antivirus companies have all had NVM4W submitted and approved... not sure why they'd still be complaining, but it could be npm related. Node 8.x.x used a version of npm with some hard coded install dependencies (which has been a thorn in the process for several years now, despite Node 8's deprecation), which create some funky behaviors.

@coreybutler as I said, it doesn't complain it just silently blocks the extract/move/copy. Nor is it because of an old npm (this still happens with the latest and LTS versions). This comment is the one with the details: https://github.com/coreybutler/nvm-windows/issues/364#issuecomment-403754900

I've just gone and had a look at the source code.

// sometimes Windows can take some time to enable access to large amounts of files after unzip, use exponential backoff to wait until it is ready

If that's true, it may be that the AV is massively slowing it down by scanning every single extracted file (of which there are ~4400). You don't seem to do anything when your retry loop gives up, which would explain why the failure is completely silent.

I reckon you either need to change how you wait for them to be "ready", or you need to extract them directly to the right place.

If you are behind enterprise firewall with proxy requiring authentication, you might have to use this fix here to copy npm folder manually: https://geektalk.tech/2019/05/29/nvm-is-a-life-saver-when-you-want-to-work-with-multiple-version-of-node-js/, as @NShulzHenko mentioned here already: https://gitter.im/coreybutler/nvm-windows?at=5e137763e409da486cd5aba1

After that, it is recommended to configure a proxy in npm, as described here
npm config set https-proxy and npm config set proxy or here

If you have to authenticate at the proxy, this might still not be sufficient, then you might have to install a local proxy that also supports providing auth tokens like px and set your proxy in npm to a local port, e.g. http://172.0.0.1:3128

Hit the same issue today. Tried few times - ran the cmder as administrator as well, use the directory without space for NVM, but no help.

C:\Development                                                                                                                         
位 nvm use 14.8                                                                                                                         
14.8.0                                                                                                                                 
Now using node v14.8.0 (64-bit)                                                                                                        

C:\Development                                                                                                                         
位 node -v                                                                                                                              
v14.8.0                                                                                                                                

C:\Development                                                                                                                         
位 npm -v                                                                                                                               
internal/modules/cjs/loader.js:1083                                                                                                    
  throw err;                                                                                                                           
  ^                                                                                                                                    

Error: Cannot find module 'C:\DevTools\nodejs\node_modules\npm\bin\npm-cli.js'                                                         
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)                                                       
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)                                                                   
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)                                                
    at internal/main/run_main_module.js:17:47 {                                                                                        
  code: 'MODULE_NOT_FOUND',                                                                                                            
  requireStack: []                                                                                                                     
}                                                                                                                                      
internal/modules/cjs/loader.js:1083                                                                                                    
  throw err;                                                                                                                           
  ^                                                                                                                                    

Error: Cannot find module 'C:\DevTools\nodejs\node_modules\npm\bin\npm-cli.js'                                                         
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)                                                       
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)                                                                   
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)                                                
    at internal/main/run_main_module.js:17:47 {                                                                                        
  code: 'MODULE_NOT_FOUND',                                                                                                            
  requireStack: []                                                                                                                     
}                                                                                                                                      

C:\Development             

@rkschamer thanks, you brought me on the right track.
On my machine, C:\Users\<usernname>\AppData\Roaming\nvm had a temp folder that contained many zip npm zip files, but I couldn't extract them because they was some kind of corrupted.
I was able to solve it, by uninstalling all versions and also deleting the temp folder with the zip files. Then I started to install the desired versions again.

To reiterate, the workaround is to disable AV scanning when installing.

An actual fix requires a better solution to the Windows unzip delay.

Was this page helpful?
0 / 5 - 0 ratings