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 fails: "Cannot find module 'semver' (node v8.4.0) #302

Open
lfurzewaddock opened this Issue Sep 15, 2017 · 39 comments

Comments

Projects
None yet
@lfurzewaddock
Copy link

lfurzewaddock commented Sep 15, 2017

If this is a question about how to use NVM4W, please use stackoverflow instead.

If this is an issue regarding antivirus, make sure you search the existing issues first.

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'm using NVM4W version:

  • 1.1.6
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.2
  • 1.1.1
  • Older
  • OTHER (Please Specify)

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 (Have you tried version 1.1.0+?)
  • 32 or 64 bit support (Have you tried version 1.1.3+?)
  • Character escaping (Have you tried version 1.1.6+?)
  • A standard shell environment (terminal/powershell)
  • A non-standard shell environment (Cmder, Hyper, Cygwin, git)

Expected Behavior

Return correct version number.

Actual Behavior

module.js:491
throw err;
^

Error: Cannot find module 'semver'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object. (C:\Users\leofu\AppData\Roaming\nvm\nvm\v8.4.0\node_modules\npm\lib\utils\unsupported.js:2:14)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
module.js:491
throw err;
^

Error: Cannot find module 'semver'
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object. (C:\Users\leofu\AppData\Roaming\nvm\nvm\v8.4.0\node_modules\npm\lib\utils\unsupported.js:2:14)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)

Steps to reproduce the problem:

nvm install 8.4.0
nvm use 8.4.0
npm -v

@coreybutler

This comment has been minimized.

Copy link
Owner

coreybutler commented Sep 15, 2017

This is an npm error, not entirely an NVM error. I'd suggest reinstalling node 8.4.0.... perhaps the npm download was bad or something was corrupted.

@Zorgatone

This comment has been minimized.

Copy link

Zorgatone commented Sep 26, 2017

@coreybutler It won't work, keeps failing even deactivating, uninstalling, manually removing the folder reinstalling and reactivating. Same error.

I even copied the npm's node_modules dependencies from another working normal installation of node 8.5.0 and still having troubles. Could you look more into it, and see what the problem is?

The nvm is a really handy tool but not working anymore, and it's a pity :(

@coreybutler

This comment has been minimized.

Copy link
Owner

coreybutler commented Sep 26, 2017

Not sure what to tell you.... I can install semver just fine with the same setup.

image

@Zorgatone Zorgatone referenced this issue Sep 26, 2017

Closed

New node v8.4.0 and 8.5.0 installation broken npm #305

10 of 28 tasks complete
@Zorgatone

This comment has been minimized.

Copy link

Zorgatone commented Sep 26, 2017

@coreybutler just opened a new issue with the details

@Zorgatone

This comment has been minimized.

Copy link

Zorgatone commented Sep 26, 2017

My own environment and the steps I used to replicate the issue here (closed duplicate): #305

@roman-spiridonov

This comment has been minimized.

Copy link

roman-spiridonov commented Oct 29, 2017

Same on the latest 8.8.1.
Not sure how to fix this through NVM as what SO suggests is just clean re-install of node. Given the nature of nvm installs not sure how to replicate these steps. So the only way to use node v8 is to just not use NVM?
https://stackoverflow.com/questions/33870520/npm-install-cannot-find-module-semver

Workaround

  1. nvm install 8.8.1 (or another version you want). Do not switch to it (yet).
  2. Download the *.zip of the same node version from official site (https://nodejs.org/en/download/current/)
  3. Substitute the contents of %APPDATA%/nvm/v8.8.1/npm for the npm folder from the downloaded archive
  4. nvm use 8.8.1
  5. Enjoy
@nmors

This comment has been minimized.

Copy link

nmors commented Oct 30, 2017

thanks @roman-spiridonov just ran into the same bug on node 8.8.1 installed via nvm on windows and your workaround seems to do the job

@slandsaw

This comment has been minimized.

Copy link

slandsaw commented Nov 8, 2017

Seems to have also worked using the latest version of node (9.1.0).

@frizadiga

This comment has been minimized.

Copy link

frizadiga commented Nov 9, 2017

seems npm thats installed from npm doesnt compatible with the node itself, you must download the zip and replace the npm module like @roman-spiridonov suggested

@hyndsite

This comment has been minimized.

Copy link

hyndsite commented Nov 11, 2017

@coreybutler is this not going to be addressed? I am seeing the exact same error exactly - anything above =< 8.0.

Unfortunately, I can't run npm i semver I get the same error.

@hyndsite

This comment has been minimized.

Copy link

hyndsite commented Nov 11, 2017

@roman-spiridonov I don't find that "npm" is a folder, but a file in the downloaded .zip. Replacing it with the downloaded one doesn't seem to resolve the semver issues for me (I know others have been successful)

@talesporto

This comment has been minimized.

Copy link

talesporto commented Nov 14, 2017

I have the same problem.

The @roman-spiridonov 's workaround work for me.

node 8.9.1
npm 5.5.1
@powellian

This comment has been minimized.

Copy link

powellian commented Nov 14, 2017

@hyndsite you need to look inside the node_modules directory - inside that is npm directory. Use that and it should work.

@hyndsite

This comment has been minimized.

Copy link

hyndsite commented Nov 15, 2017

Thanks @powellian I found that yesterday and was going to post a new update to @roman-spiridonov message - that the correct path is %APPDATA%/nvm/v8.8.1/node_modules/npm

The "npm" file in the /nvm/vx.x.x path helped to confuse the matter.

@benavern

This comment has been minimized.

Copy link

benavern commented Nov 17, 2017

Thank you, it works, But now I am wondering why is the package that nvm downloads & the one we download is different ?

@Akamaozu

This comment has been minimized.

Copy link

Akamaozu commented Jan 16, 2018

Same problem with 8.9.0 and @roman-spiridonov's workaround saved the day.

Like @benavern I'm curious why the package nvm installs is different from the one in the official repo.

@earth55

This comment has been minimized.

Copy link

earth55 commented Jan 31, 2018

Same on the latest 8.9.4.
The error was solved by deleting directory 'C:\Users\yourname\AppData\Roaming\nvm\v*' and re-executing 'nvm install'.

@apptaro

This comment has been minimized.

Copy link

apptaro commented Feb 15, 2018

Workaround:

If you encounter this issue and you're using Windows 10, enable long paths using Registry Editor or Local Group Policy Editor.

Ref: #305 (comment)
Ref: https://superuser.com/a/1119948

But for me, I still needed to do @roman-spiridonov's workaround. However, I couldn't copy npm folder in Explorer, instead I needed to use robocopy:

robocopy "C:\Users\username\Downloads\node-v8.9.4-win-x64\node_modules\npm" "C:\Users\username\AppData\Roaming\nvm\v8.9.4\node_modules\npm" /mir

@jaxer

This comment has been minimized.

Copy link

jaxer commented Feb 20, 2018

alternative it to move nvm root. do nvm root C:\nvm before installing new node.
might need to also copy extra files to new root.
if already installed, then:

nvm uninstall 8.x.x
nvm root C:\nvm
copy /Y %APPDATA%\nvm\* C:\nvm
nvm install 8.x.x
@codeshell

This comment has been minimized.

Copy link

codeshell commented Feb 26, 2018

I experienced the same problem (Error: Cannot find module 'semver').

Some hints to get you going:

File compare (using official zip file) showed that there are indeed > 4k files and folders missing under node_modules\npm. It looks like the unzipping is aborted. Checked for v8.9.1 and v8.9.4: all node_modules alphabetically behind libnpx are missing. Wouldn't be surprised if it relates to those ridiculously nested folder structure: ...\nvm\v8.9.4\node_modules\npm\node_modules\libnpx\node_modules\yargs\node_modules\read-pkg-up\node_modules\read-pkg\node_modules\load-json-file\node_modules\parse-json\node_modules\error-ex\node_modules\is-arrayish\

I took the current master of nvm-windows, added some debug information to the install function within nvm.go, compiled it (with Go 1.10 win x64) and exchanged the nvm.exe with the new one. Result:

  • The npm zip file which is downloaded to the temp directory is in fact the official one. (@benavern , @Akamaozu )
  • The zip file was fully extracted within the temp directory and moved to the version-specific folder. No missing files.

Now for the surprising part, as I tried finding the regression:

  • Checked out tag 1.1.6, compiled (without any changes), replaced nvm.exe with the new one, deleted v8.9.4, ran nvm install 8.9.4 => successful, no missing files
  • Checked out tag 1.1.5, compiled (without any changes), replaced nvm.exe with the new one, deleted v8.9.4, ran nvm install 8.9.4 => successful, no missing files
  • Replaced nvm.exe with the original one from the official nvm-windows setup (1.1.5), deleted v8.9.4, ran nvm install 8.9.4 => still error, files missing.

It looks for me like there is an issue with the build process and/or environment.

Would be great if someone else could try if recreating the nvm.exe via build.bat or go build src/nvm.go solves the problem for him/her as well.

HTH, codeshell

This was referenced Feb 28, 2018

@LokeshNagarajan

This comment has been minimized.

Copy link

LokeshNagarajan commented Mar 17, 2018

Delete npm folder from below folder
C:\Users\username\AppData\Roaming\npm
after => npm install
Its Working Fine for me!....

@cooploops

This comment has been minimized.

Copy link

cooploops commented Apr 6, 2018

Just ran into this issue today and this worked for me.

  1. Open a bash terminal
  2. CD into C:\Users\username\AppData\Roaming\npm\node_modules\
  3. should see a package.json
  4. yarn install
@dev7ch

This comment has been minimized.

@kedarkolhatkar

This comment has been minimized.

Copy link

kedarkolhatkar commented Apr 21, 2018

@codeshell Thanks for your analysis. I found the issue to be due to the long paths that are not supported on Windows. For me even after downloading npm zip file and replacing contents of C:\Users\yourname\AppData\Roaming\nvm\9.11.1\npm I got the error. In fact I could not copy all files from downloaded npm zip file due to long names.

To avoid this I uninstalled node version 9.11.1, then uninstalled nvm. Reinstalled nvm at C:\nvm. Now my normal 'nvm install 9.11.1' works just fine and 'npm' is also in good state confirmed by running 'npm -v'.

I know this is a pretty drastic fix but just need to do one time.

@maheshigunaratne

This comment has been minimized.

Copy link

maheshigunaratne commented May 1, 2018

I followed These steps and it solved my issue

  1. uninstall Node.js
  2. Remove the content of the following folders
    C:\Users<user-name>\AppData\Roaming\npm-cache
    C:\Users<user-name>\AppData\Roaming\npm
    C:\Program Files\nodejs
  3. Then again install Node https://nodejs.org/en/
@BoyanPalagachev

This comment has been minimized.

Copy link

BoyanPalagachev commented May 17, 2018

installing the node through nvm 1.6.0 worked for me

@slandsaw

This comment has been minimized.

Copy link

slandsaw commented May 31, 2018

In my case, the paths were just too long. I chose c:\nvm as the install directory version manager and c:\nodejs for the symlink directory. That seemed to resolve the issue for me.

@leifurhauks

This comment has been minimized.

Copy link

leifurhauks commented Jun 8, 2018

I had the same problem with node v10.4.0 and the workaround from roman-spiridonov worked for me.

I had already removed %AppData%\npm etc. before installing nvm-windows.

@NicTorgersen

This comment has been minimized.

Copy link

NicTorgersen commented Jun 20, 2018

Tried getting 10.4.1 up and running, had problems at first.

Got it to work after deleting the folder from install location manually and installing via nvm again. Not sure whether this is too long of a path (obviously not) C:\Users\muser\AppData\Roaming\nvm\v10.4.1.

@rgomez90

This comment has been minimized.

Copy link

rgomez90 commented Jul 1, 2018

Same problem with v10.5.0 and roman-spiridonovs solution worked for me as well.

@shadeofgod

This comment has been minimized.

Copy link

shadeofgod commented Jul 6, 2018

I have the same probem when installing the latest node v10.6.0, then I just uninstalled it and switched to v8.11.3, problem solved.

I also tried download directly the npm-v6.1.0.zip, it do have some errors when unzipping.

@uilyam

This comment has been minimized.

Copy link

uilyam commented Jul 8, 2018

Experienced the same issue as @shadeofgod with 10.6.0. Switching to 8.11.3 solved it.

@PutziSan

This comment has been minimized.

Copy link

PutziSan commented Jul 10, 2018

problem persists with 10.6.0-64bit for a complete clean first install. (no node/npm before). roman-spiridonovs solution continues to work (for me the npm-folder can now be found in [...node]\node_modules\npm)

@nickcoad

This comment has been minimized.

Copy link

nickcoad commented Jul 16, 2018

Why is this still an issue after almost an entire year?

metanomi added a commit to metanomi/nvm-windows that referenced this issue Jul 18, 2018

getting Access Denied at os.Rename()
os.Rename() of node_modules/npm on Node version installs throws Access Denied (win 7) -- seems to be this issue coreybutler#302 and that seems to be caused by a golang behavior change in os.Rename() described in golang/go#14527 ...fixed by using copy package instead
@damianhofmannwork

This comment has been minimized.

Copy link

damianhofmannwork commented Aug 29, 2018

Just encountered this issue on Windows 10.

Enabling Win32 long paths fixed the issue. See post from @apptaro (2018-02-15)

After enabling long paths, I rebooted Windows to make the change apply.
I also had to delete the broken npm install manually.

After that, I could install the npm again using nvm.

I feel, nvm under Windows should issue warnings if long paths aren't enabled. nvm install also should not fail silently.

@GrahamTheCoder

This comment has been minimized.

Copy link

GrahamTheCoder commented Aug 29, 2018

For me:

  • nvm install 9.11.2 was the last version I found that worked through nvm.
  • Overwriting with the zip file from the website works on any version.
  • The long paths fix didn't seem to work (though I don't think I tried a machine restart after changing the registry setting).

This is the powershell script we use for new starters. Hopefully after a reboot they should be able to update to a later version is the idea.

# Get Chocolatey which is required for the rest of this script
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n=allowGlobalConfirmation
choco upgrade chocolatey

choco upgrade nvm
$env:NVM_HOME = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("NVM_HOME","Machine"))
$env:NVM_SYMLINK = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("NVM_SYMLINK","Machine"))
$env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User"))

# Enable long paths in windows - may avoid npm issue https://github.com/coreybutler/nvm-windows/issues/302
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 -PropertyType DWORD -Force | Out-Null
New-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 -PropertyType DWORD -Force | Out-Null

nvm install 9.11.2
nvm use 9.11.2
@momochanmo

This comment has been minimized.

Copy link

momochanmo commented Dec 4, 2018

Not sure what to tell you.... I can install semver just fine with the same setup.

image

I think running "npm install" would solve the problem, as it did with me ;)

@GrahamTheCoder

This comment has been minimized.

Copy link

GrahamTheCoder commented Dec 4, 2018

I believe @momochanmo had just forgotten to install the semver package in their project. It has the same error message but this is a totally different issue.

To recap: This thread is about the fact that nvm installs a corrupted version of npm with a missing/corrupted version of the semver package, which renders it inoperable.

The most likely root cause suggested so far is that a bug / behaviour change introduced into the Go compiler about 3 years ago causes an error that's being silently swallowed during installation. See #370.

So if you know someone who works with Windows stuff and is enthusiastic about Go, now's a good time to tap them on the shoulder and offer them this excellent career development opportunity 😅

@Pimentelk

This comment has been minimized.

Copy link

Pimentelk commented Feb 1, 2019

I followed These steps and it solved my issue

  1. uninstall Node.js
  2. Remove the content of the following folders
    C:\Users\AppData\Roaming\npm-cache
    C:\Users\AppData\Roaming\npm
    C:\Program Files\nodejs
  3. Then again install Node https://nodejs.org/en/

Following this worked for me. You are a life saver!!!!! thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment