0

I'm trying to install node on MacOS using the following command:

sudo npm install -g node

This yields the following output:

> node@12.6.0 preinstall /usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node
> node installArchSpecificPackage

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EACCES: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/5e859640'
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! path /Users/bernhard/.npm/_cacache/tmp/ef2c2113
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR!  [OperationalError: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'] {
npm ERR!   cause: [Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'open',
npm ERR!     path: '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR!   },
npm ERR!   isOperational: true,
npm ERR!   stack: "Error: EACCES: permission denied, open '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/Users/bernhard/.npm/_cacache/tmp/ef2c2113'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/node_modules/node-bin-setup/index.js:27
        throw e;
        ^

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/bin'
    at Object.mkdirSync (fs.js:764:3)
    at ChildProcess.<anonymous> (/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/node_modules/node-bin-setup/index.js:24:10)
    at ChildProcess.emit (events.js:203:13)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/usr/local/lib/node_modules/node-darwin-x64/lib/node_modules/node-darwin-x64/lib/node_modules/node/bin'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node@12.6.0 preinstall: `node installArchSpecificPackage`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node@12.6.0 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bernhard/.npm/_logs/2019-07-21T16_20_19_759Z-debug.log

Running sudo npm cache clean before-hand does not make a difference. I checked the permissions on the _cacache folder and my user has full permissions to that folder.

Any ideas as to what may be causing this issue?

bgh
  • 1,986
  • 1
  • 27
  • 36
  • An answer (which should probably be moved to comments) asked why someone would install node with npm and if that's even possible. Here `npm install -g node` is installing [a global module called `node`](https://www.npmjs.com/package/node) (not the same as the NodeJS executable) to manage node versions. – stealththeninja Jul 21 '19 at 16:40
  • Possible duplicate of [npm throws error without sudo](https://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo) – stealththeninja Jul 21 '19 at 16:41
  • How do you currently have npm installed without node? I'm not going to say its impossible, but I've never seen npm installed without node. Installing node generally will also install npm. What are you hoping to achieve here? Upgrade? First time install? – Jon Jul 21 '19 at 16:31

1 Answers1

0

As other users mentioned, npm is essentially part of Node.js (and npm install -g node will instead install a global module called "node", which is not the same as the Node.js node executable).

My troubles began after I had to update node and when the (erroneous) npm command for doing that failed, I npm-uninstalled node so that I could re-install it. Node.js was, in fact, uninstalled by this point (at least partially - either that, or broken).

Re-installing Node.js by running the installer downloaded from the Node.js website fixed the issue. In future, I shall update Node.js using one of the recommended methods, like the one described in this post.

bgh
  • 1,986
  • 1
  • 27
  • 36