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.
[ ] Windows Server 2016
[ ] My Windows installation is non-English.
Return correct version number.
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.
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.
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)
nvm install 8.4.0
nvm use 8.4.0
npm -v
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.
@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 :(
Not sure what to tell you.... I can install semver
just fine with the same setup.
@coreybutler just opened a new issue with the details
My own environment and the steps I used to replicate the issue here (closed duplicate): #305
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
nvm install 8.8.1
(or another version you want). Do not switch to it (yet).%APPDATA%/nvm/v8.8.1/npm
for the npm
folder from the downloaded archivenvm use 8.8.1
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
Seems to have also worked using the latest version of node (9.1.0).
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
@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.
@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)
I have the same problem.
The @roman-spiridonov 's workaround work for me.
node 8.9.1
npm 5.5.1
@hyndsite you need to look inside the node_modules directory - inside that is npm directory. Use that and it should work.
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.
Thank you, it works, But now I am wondering why is the package that nvm downloads & the one we download is different ?
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.
Same on the latest 8.9.4.
The error was solved by deleting directory 'C:\Users\yourname\AppData\Roamingnvm\v*' and re-executing 'nvm install'.
If you encounter this issue and you're using Windows 10, enable long paths using Registry Editor or Local Group Policy Editor.
Ref: https://github.com/coreybutler/nvm-windows/issues/305#issuecomment-345024594
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
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
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:
Now for the surprising part, as I tried finding the regression:
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
Delete npm folder from below folder
C:\Usersusername\AppData\Roamingnpm
after => npm install
Its Working Fine for me!....
Just ran into this issue today and this worked for me.
1) Open a bash terminal
2) CD into C:\Usersusername\AppData\Roamingnpm\node_modules\
3) should see a package.json
4) yarn install
@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\Roamingnvm\9.11.1npm 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.
I followed These steps and it solved my issue
installing the node through nvm 1.6.0 worked for me
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.
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.
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
.
Same problem with v10.5.0 and roman-spiridonovs solution worked for me as well.
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.
Experienced the same issue as @shadeofgod with 10.6.0. Switching to 8.11.3 solved it.
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
)
Why is this still an issue after almost an entire year?
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.
For me:
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
Not sure what to tell you.... I can install
semver
just fine with the same setup.
I think running "npm install" would solve the problem, as it did with me ;)
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 https://github.com/coreybutler/nvm-windows/pull/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 馃槄
I followed These steps and it solved my issue
- uninstall Node.js
- Remove the content of the following folders
C:\Users\AppData\Roamingnpm-cache
C:\Users\AppData\Roamingnpm
C:\Program Files\nodejs- Then again install Node _https://nodejs.org/en/_
Following this worked for me. You are a life saver!!!!! thanks <3
Most helpful comment
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
nvm install 8.8.1
(or another version you want). Do not switch to it (yet).%APPDATA%/nvm/v8.8.1/npm
for thenpm
folder from the downloaded archivenvm use 8.8.1