nvm-windows: 'Cannot find module' when calling NPM

Everything seems properly installed, executing nvm list gives…

  0.12.3
* 0.10.38 (Currently using ?-bit executable)

However when I try to run npm, error pops out…

module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-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:935:3

It is right about it, there is no npm module installed in node_modules directory for either version of node installed.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 39 (9 by maintainers)

Most upvoted comments

Unfortunately, I don’t have a Win 2012 server to test on right now.

The 100% manual way to do this:

  1. Identify the appropriate version of npm from the node distro service for the version you want to set this up for.
  2. Go into C:\Program Files\nodejs (or wherever you setup the symlink).
  3. Create a directory called node_modules. Download the appropriate npm release. Extract the contents. At this point you should simply have a folder called npm within the node_modules directory.
  4. Go back to the root directory (C:\Program Files\nodejs… same level as the node_modules, node.exe, and node64.exe). Create the npm and npm.cmd` files. The code is available in this gist.

If you’re seeing the (Currently using ?-bit executable), there are two solutions. First, you can build from source (the master branch has a fix for this). The alternative is to install each version of node (i.e. 32 bit and 64-bit) separately. In @FredyC’s example, you could do both nvm install 0.10.38 32 and nvm install 0.10.38 64. Alternatively, you can find the node executable, copy it, and paste it as either node32.exe or node64.exe. Yes, it’s an ugly hack.

NVM isn’t recognizing the appropriate version of the node executable due to a missing case statement in the code. The aforementioned hack essentially resets the state so it works correctly. After that, npm should work properly. If not, let me know which version of Windows you’re running and whether you had anything installed prior to the NVM install (i.e. a prior version of node, io.js, etc).

@PlatinumEagle I was in a similar situation…on a Dell computer with McAfee pre-installed. Disabling McAfee’s “Real-Time Scanning”, uninstalling NVM for Windows (NVM4W), and re-installing NVM4W from a Command Prompt that was running as an Administrator fixed the problem. I was able to re-enable McAfee with no additional issues.

Exact same symptoms, root cause was McAfee interfering (came pre-installed on my Dell) with the installation. Disabled real time scanning and reinstalled nvm-windows. Then everything worked properly.

Note: There is a note about McAfee interference here in the readme for this project (https://github.com/coreybutler/nvm-windows#antivirus), but the referenced symptoms are not the same.

I think I’m running into the same issue

My Environment

  • Windows 10

I’m using NVM4W version:

  • 1.1.7

I’ve tried using cmd and the built in win command line interface, both with admin privileges and without, with the same result.

λ npm
internal/modules/cjs/loader.js:584
    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:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
internal/modules/cjs/loader.js:584
    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:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Update 10/4

I confirmed that my node_modules also ended up empty upon installation. Which is kind of strange as nothing suggests otherwise. Output for installing v9.11.2:

λ nvm install 9.11.2
Downloading node.js version 9.11.2 (64-bit)...
Complete
Creating C:\Users\MyUser\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 9.11.2

And the same output as before my update when I try to run npm.

So I installed a copy of v9.11.2 outside of nvm using the official installer. Copied the npm files from that installation’s npm_modules to my nvm installation, uninstalled the standalone version, and lo and behold, my nvm installation isn’t complaining anymore when I run npm.

I’ve been running all commands and installations using admin privileges so that shouldn’t be the issue here, I’m not a regular windows user though so I might have missed something or gotten something wrong, who knows …

It would be nice if NVM could detect this failure, provide an appropriate error message, and roll back the install

Do you see the (Currently using ?-bit executable) or do you see (Currently using 64-bit executable) when you do an nvm list? It’s a critical answer because the code can prevent the npm installation.

I just had the same problem and “solved” it by running NVM as administrator.