错误:EACCES:权限被拒绝,使用 npm 安装 sth 时出现 mkdir

Fel*_*ser 3 node.js npm

每次我尝试使用 npm(在这种情况下为电子打包器)安装某些东西时,我都会遇到这个错误。我该如何解决这个问题?

我已经尝试通过 chmod 更改 .npm 的权限来给我访问权限,但它没有用,我还尝试了另一个节点版本(通过 nvm 安装:node -v 12.1.0;npm -v 6.9。 0) 并且它也不起作用。

$ npm install electron-packager --save-dev
npm ERR! path /Users/felixmoser/.npm/_cacache/index-v5/15/a0
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR!  [OperationalError: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR!   cause: [Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR!   },
npm ERR!   isOperational: true,
npm ERR!   stack: 'Error: EACCES: permission denied, mkdir ' +
npm ERR!     "'/Users/felixmoser/.npm/_cacache/index-v5/15/a0'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0',
npm ERR!   parent: 'electron-packager'
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).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/felixmoser/.npm/_logs/2019-05-01T14_11_08_530Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我实际上不知道我现在还应该尝试什么,希望你们能帮我解决这个问题!

MD *_*YON 23

更改.npm文件夹的所有权,就我而言,我无法找出解决方案,所以我使用

sudo chown -R $(whoami) ~/.npm
Run Code Online (Sandbox Code Playgroud)


Sty*_*tyx 7

只需将~/.npm文件夹的所有者更改为您自己:

sudo chown -R felixmoser ~/.npm
Run Code Online (Sandbox Code Playgroud)

您需要输入密码才能拨打sudo