NPM update on Windows fails to recognize new version

I’ve been trying to play with ReactJS lately, but when it came time to do an npm install on my personal Windows machine (I had been working on my work’s Macbook Pro), I received a number of errors including:

$ npm install
npm WARN package.json project-name@1.0.0 No repository field.
npm WARN optional dep failed, continuing fsevents@1.0.8
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine is-buffer@1.1.3: wanted: {"node":">=0.12"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm ERR! Error: EPERM, open 'C:\Users\username\AppData\Roaming\npm-cache\f1c9fdf5-cache-inherits-2-0-1-package-tgz.lock'
npm ERR!  { [Error: EPERM, open 'C:\Users\username\AppData\Roaming\npm-cache\f1c9fdf5-cache-inherits-2-0-1-package-tgz.lock']
npm ERR!   errno: 50,
npm ERR!   code: 'EPERM',
npm ERR!   path: 'C:\\Users\\username\\AppData\\Roaming\\npm-cache\\f1c9fdf5-cache-inherits-2-0-1-package-tgz.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd c:\pv\www\project-name
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! path C:\Users\username\AppData\Roaming\npm-cache\f1c9fdf5-cache-inherits-2-0-1-package-tgz.lock
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, open 'C:\Users\username\AppData\Roaming\npm-cache\f1c9fdf5-cache-inherits-2-0-1-
package-tgz.lock'
npm ERR! not ok code 0

I’d also get something like this more often than not:

npm ERR! Linux 3.13.0-36-generic
npm ERR! argv "node" "/usr/bin/npm" "install"
npm ERR! node v0.10.32
npm ERR! npm  v2.1.0
npm ERR! path /home/user/.npm/4c25afa1-ncis-npm-vinyl-0-4-3-package-tgz.lock
npm ERR! code EEXIST
npm ERR! errno 47

To fix these errors you will need to upgrade nodejs and npm, then there are also some additional steps because …Windows.

1. Install the latest version of NodeJS.
https://nodejs.org/en/download/
Be sure to download the 64-bit version explicitly. The default Windows installer is 32-bit.
This will install the latest node and npm versions.

This is where it got a littly dicey for me. There are essentially two versions of npm now installed on your machine.
See here (https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows for more details but here’s the gist:

By default, npm is installed alongside node in C:\Program Files (x86)\nodejs. npm’s globally installed packages (including, potentially, npm itself) are stored separately in a user-specific directory (which is currently C:\Users\\AppData\Roaming\npm). Because the installer puts C:\Program Files (x86)\nodejs before C:\Users\\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm@.

2. You will need to add the location of the proper npm version to your environment variables.

Right Click on My Computer > Select Properties > Find the Path variable under System Variables:

Add “%appdata%\npm;” before “C:\Program Files (x86)\nodejs\”

3. To be sure, we will now also change the shortcuts to npm within the nodejs directory

In “C:\Program Files\nodejs” rename “npm” and “npm.cmd” to “npm.old” and “npm.cmd.old”, respectively.

4. Close your cmd window and reopen a new one. This should recognize your new environment variables.
If you try an npm install, things should work as expected.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *