我在“npm install”上得到“拒绝访问”
Posted
技术标签:
【中文标题】我在“npm install”上得到“拒绝访问”【英文标题】:I get "access denied" on `npm install` 【发布时间】:2019-11-15 13:44:46 【问题描述】:我正在安装一个新项目,并在npm install
时收到以下错误。
我已经尝试过here 的解决方案,但这并没有什么不同。在终端中输入这些行不会产生任何输出,然后npm install
会导致同样的错误。
知道如何解决这个问题吗?
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/5134a7c3'd in 126ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/fcf123f8'^1.1.7 fetched in 96ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/f8a35f38'd in 39ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/3914ffcc'4ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/98bb7e0d'tched in 65ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/5196be2e'63ms
Unhandled rejection Error: EACCES: permission denied, open '/home/user/.npm/_cacache/tmp/1cf3fdde'fetched in 394ms
npm WARN checkPermissions Missing write access to /projects/user-portal/node_modules
npm WARN checkPermissions Missing write access to /projects/user-portal/node_modules/@google-cloud
npm WARN bookshelf@0.10.4 requires a peer of knex@>=0.6.10 <=0.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.3.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.3.1 requires a peer of popper.js@^1.14.7 but none is installed. You must install peer dependencies yourself.
npm WARN portal@1.0.0 license should be a valid SPDX license expression
npm ERR! path /projects/user-portal/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/projects/user-portal/node_modules'
npm ERR! Error: EACCES: permission denied, access '/projects/user-portal/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/projects/user-portal/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/projects/user-portal/node_modules'
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).
更新
我尝试了sudo chown -R user:user /projects/
然后npm install
,但这导致了以下错误:
sharp@0.18.4 install /projects/user-portal/node_modules/sharp
node-gyp rebuild
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at getNotFoundError (/usr/lib/node_modules/npm/node_modules/which/which.js:13:12)
gyp ERR! stack at F (/usr/lib/node_modules/npm/node_modules/which/which.js:68:19)
gyp ERR! stack at E (/usr/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Linux 3.10.0-957.21.3.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /projects/user-portal/node_modules/sharp
gyp ERR! node -v v8.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
【问题讨论】:
这两条命令的结果是什么?whoami
和 ls -la /projects
。最好在你的主目录上创建项目。
谢谢,whoami
返回user
。 ls -la /projects
返回:total 4
drwxr-xr-x 3 user root 25 Jul 4 20:46 .
drwxr-xr-x 22 root root 295 Jul 4 21:45 ..
drwxr-xr-x 18 user user 4096 Jul 4 21:18 user-portal
我正在使用 IDE (Codenvy),这就是为什么该项目位于工作区的子文件夹中。
是否安装了make?快速检查将是make -v
啊,它确实不是,也不是它运行!谢谢!
【参考方案1】:
我只是超级用户这样做:
sudo npm install -g
对于全球的东西
只是:
sudo chown -R [user]:[user] /projects/
或创建一个“项目”组并将自己添加到该组并让该组拥有它。
不过,如果我是你,我会像 @agtabesh 建议的那样将你的项目移动到你的主目录。
【讨论】:
谢谢,我用这个建议的结果更新了 OP。我不喜欢在这里使用 sudo,不幸的是 Codenvy 无法将项目移动到主目录。【参考方案2】:先运行这一行:
sudo chown -R $USER /usr/local/lib/node_modules
解释:
https://flaviocopes.com/npm-fix-missing-write-access-error
【讨论】:
欢迎来到 SO。请直接在答案中添加一些描述以上是关于我在“npm install”上得到“拒绝访问”的主要内容,如果未能解决你的问题,请参考以下文章
npm install web3 到 Appcelerator Titanium SDK > 6.x
我在本地计算机上的何处放置'$ npm install $ npm development']]
`npm install` 不工作。未处理的拒绝错误:EISDIR:对目录的非法操作