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

Created on 18 May 2015  路  39Comments  路  Source: coreybutler/nvm-windows

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.

Installer Issue

Most helpful comment

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.

All 39 comments

Is there a manual workaround for this issue? Need to be able to get the node_modulesnpm directory and content to show up on installs...

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

Yes, I had a prior version of Node (0.12.2) installed, and told NVM to manage it when I was prompted. Now when I install new versions, it doesn't install the npm module binaries. How do I get the npm modules to populate now?

Host: Windows 2012 R2 64-bit

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 see the: (Currently using ?-bit executable)

Go into the directory where you installed NVM for Windows, find the 0.12.2 folder (or whatever version is currently in use), and take notice if there is only a single .exe. If it is node64.exe or node32.exe, make a copy called node.exe. You should have 2 .exe files.

Then run nvm list again. It should no longer show the question mark. If this is the case, try npm. If it still doesn't work, you can uninstall and reinstall the version, at which point all of the npm files should be available.

Copied node64.exe to node.exe

Still get:
nvm list

  • 0.12.2 (Currently using ?-bit executable)

npm module is also still missing.

Ah, probably need to rename node64.exe to node32.exe... I forgot that step.

Doesn't seem to be working...

d:appsnvm>nvm install 0.12.2
Downloading node.js version 0.12.2 (64-bit)... Complete
Downloading npm version 2.7.4... Complete
Installing npm v2.7.4...

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

nvm use 0.12.2

d:appsnvm>cd v0.12.2

d:appsnvmv0.12.2>ren node64.exe node32.exe

d:appsnvmv0.12.2>cp node32.exe node.exe

d:appsnvmv0.12.2>nvm list

  • 0.12.2 (Currently using ?-bit executable)

d:appsnvmv0.12.2>dir
07/16/2015 09:06 PM

.
07/16/2015 09:06 PM ..
07/16/2015 09:06 PM 11,104,640 node.exe
07/16/2015 09:03 PM 11,104,640 node32.exe
07/16/2015 09:03 PM node_modules
07/16/2015 09:03 PM 340 npm
07/16/2015 09:03 PM 209 npm.cmd
4 File(s) 22,209,829 bytes
3 Dir(s) 72,946,851,840 bytes free

Which version of Windows are you running?

Windows 2012 R2 64-bit

After I run 'nvm use 0.12.2', I see that it renames the exe's to node.exe and node64.exe

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.

This seems to be caused by #75

try going to your nvm folder then to the version that is causing you problems then double click the npm.cmd file.

I had the same problem, i think its because of windows smart screen. The fix that worked for me, was to uninstall nvm, then reinstall, changing the install directory from the default (Appdata) to c:nvm. Everything works perfect. Which leads me to think that its a permission thing...

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.

OS: Win 7 - 64-bit
nvm installation: C:/nvm, version - 1.1.0
node installation: 6.2.2


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:UsersRework>node -v
v6.2.2

C:UsersRework>npm -v
module.js:442
throw err;
^

Error: Cannot find module 'C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
module.js:442
throw err;
^

Error: Cannot find module 'C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3

Its working now, I just downloaded node 6.2.2 src folder from github site, and copied node_modules folder in nvm folder inside 6.2.2 version of node folder.
I would like to understand why nvm doesn't copy all these files automatically and we have to do it manually.

I actually just installed 6.2.2 on my Windows 10 machine.... no problems at all.

@invinciblemuffi - NVM4W _does_ do this. If something doesn't happen automatically, it is almost always the OS preventing a command from running, or some other 3rd party software (like antivirus). Furthermore, Windows 7 reached EOL and is not technically supported.

remove the system env path before relate to npm and node, but remain nvm, it's work for me

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

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

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

2017 and McAfee still giving me grief with installations! Thanks for PlatinumEagle for giving me the hint...

This should no longer be happening in the latest version, so I'm closing it. If people continue to run into this issue, post here and I'll reopen.

For those dealing with antivirus: Remember to make sure your AV definitions are up to date. NVM4W is whitelisted with McAfee and all other major AV systems.

It's also important to remember that elevated administrative privileges are required for this to work. That's a stipulation of the operating system.... those are simply the permissions Windows requires to create symlinks or access C:\Program Files (considered a sensitive directory)..

It's working fine on Mac but giving error on linux server...

wdio wdio.deskcustomreporter.conf.js

module.js:442
throw err;
^
Error: Cannot find module '../build/lib/cli.js'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/srv/fronttest/fronttest/releases/4-fronttest-master-20170721000921/node_modules/.bin/wdio:5:1)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)


"devDependencies": {
"@housing/filter-encoder": "^1.0.31",
"concurrently": "^3.5.0",
"mocha": "^3.2.0",
"webdriverio": "^4.5.2"
},
"dependencies": {
"child_process": "^1.0.2",
"es6-promise": "^4.0.5",
"express": "^4.15.3",
"octokat": "^0.4.18",
"underscore": "^1.8.3"
},
"version": "0.0.1"
}

@sanjaychaudhari1821 - this is NVM for _Windows_. I think you're looking for nvm.

Still getting this issue when installing Node 6.11.3 or 6.12.0, did not check other node6 versions. Works fine with node 8.9.1 and 9.1.0. It worked before but now does not anymore...

I run as admin
nvm install 6.12.0

Downloading node.js version 6.12.0 (64-bit)...
Complete
Creating C:\Users\D068725\AppData\Roaming\nvm\temp

Downloading npm version 3.10.10... Complete
Installing npm v3.10.10...

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

nvm use 6.12.0

then i run nvm use 6.12.0

Now using node v6.12.0 (64-bit)

Then i run npm --version

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:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496: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:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496:3

When i look into the node_modules folder in folder 6.12.0 it is empty.

BTW the download seems to work, in the temp folder i can see that an npm-xxx.zip is downloaded and extracted. However it does not seem to be copied over...

I've just had this issue!

I uninstalled my nodeJS install using nvm uninstall (then followed the instructions to delete folder manually)

then ran NVM under admin priv to re-install, this seemed to have worked by removing and reinstall as admin!

I am having this issue with a fresh install. I have tried the following permutations with the same result, an empty node_modules folder.

  1. Install to default directories, run terminal as user, execute nvm commands.
  2. Install to default directories, run terminal as root, execute nvm commands.
  3. Install to C:\Users\q4i2\nvm and C:\Users\q4i2\node, run terminal as user, execute nvm commands.
  4. Install to C:\Users\q4i2\nvm and C:\Users\q4i2\node, run terminal as root, execute nvm commands.

Windows 10 guest inside VMWare Fusion 10.0.1
nvm-windows 1.1.6
Mcafee 5.0.6.220 with latest definitions. Unfortunately this is a work machine so I cannot disable it to test.

C:\Users\q4i2
位 nvm install 4.8.7
Downloading node.js version 4.8.7 (64-bit)...
Complete
Creating C:\Users\q4i2\nvm\temp

Downloading npm version 2.15.11... Complete
Installing npm v2.15.11...

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

nvm use 4.8.7

C:\Users\q4i2
位 nvm use 4.8.7
Now using node v4.8.7 (64-bit)

C:\Users\q4i2
位 npm -v
module.js:327
    throw err;
    ^

Error: Cannot find module 'C:\Users\q4i2\node\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:140:18)
    at node.js:1043:3
module.js:327
    throw err;
    ^

Error: Cannot find module 'C:\Users\q4i2\node\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:140:18)
    at node.js:1043:3

C:\Users\q4i2
位 nvm root

Current Root: C:\Users\q4i2\nvm

C:\Users\q4i2
位 dir C:\Users\q4i2\nvm\v4.8.7\node_modules\
 Volume in drive C is OSDisk
 Volume Serial Number is 5AC4-C122

 Directory of C:\Users\q4i2\nvm\v4.8.7\node_modules

01/10/2018  11:40 AM    <DIR>          .
01/10/2018  11:40 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  14,723,813,376 bytes free

The offending line seems to be Installing npm v2.15.11... as it does not change to Installing npm v2.15.11... Complete as the previous download task does.

I am getting this error while Altering table in database.....

C:UsersGauravNode.js>node demo_alterTable.js
module.js:540
throw err;
^

Error: Cannot find module 'C:UsersGauravNode.jsdemo_alterTable.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

---------------------------------------------Source Code------------------------
////filename- demo_alterTable.js
var mysql = require('mysql');

var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "nodejs"
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "ALTER TABLE customers ADD COLUMN id INT AUTO_INCREMENT PRIMARY KEY";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Table altered");
});
});

@GauravSinghPawar That issue seems to have nothing to do with npm so you should probably create another issue. This ticket is for npm which should be installed by default but isn't. The file C:\Users\Gaurav\Node.js\demo_alterTable.js is not installed on every user's machine by default so I am very doubtful that you are encountering the same issue and/or root cause. It looks like the issue you are having is that the file is there, but it cannot be read for some reason. The npm issue can be "patched" by putting the files there manually.

When you do create a new issue, it would be best if you included logs and version information. Minimally, I would expect to see the nvm, node.js and Windows version numbers along with a directory listing of C:\Users\Gaurav\Node.js\ and its files' privileges. Also, what user you are running node as and whether it is with elevated permissions or not.

I had the same problem after installing Electron Globally.
Solution: I created the npm folder manually, then reinstalled with repair action.

simple restart solved the issue

the manual fix that @coreybutler provided worked for me

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

I was getting this but for me it was the same issue as HERE. Fixed it by disabling McAfee before running nvm install from an elevated command prompt.

I'm suspecting that my issue is the same as @helzgate but I can't test it because of corporate reasons.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webspecialist picture webspecialist  路  5Comments

fredericrous picture fredericrous  路  3Comments

janpio picture janpio  路  3Comments

David263 picture David263  路  3Comments

petrovicz picture petrovicz  路  4Comments