我已经通过弹性 Beanstalk 提供了一个默认的干净的 Node.js 应用,并且有一个 Node.js 脚本尝试在项目目录(/var/app/current/deploy-dist
)内运行 npm install
,但是出现了以下权限错误:
npm WARN locking Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking at Error (native)
npm WARN locking /tmp/.npm/_locks/staging-f212e8d64a01707f.lock failed { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking at Error (native)
npm WARN locking errno: -13,
npm WARN locking code: 'EACCES',
npm WARN locking syscall: 'open',
npm WARN locking path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm WARN deploy-dist No description
npm WARN deploy-dist No repository field.
npm WARN deploy-dist No license field.
npm ERR! Linux 4.4.35-33.55.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/npm" "install"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! path /tmp/.npm/_locks/staging-f212e8d64a01707f.lock
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /var/app/current/deploy-dist/npm-debug.log
package.json
只是一个:
{
"dependencies": {
"node-fetch": "^1.3.3"
}
}
使用sudo运行npm install
显然可行,但最好避免这种解决方案。
根据npm
文档建议,将NPM_CONFIG_PREFIX
设置为~
目录下的一个目录也无效,问题仍然存在。
我怀疑问题出在错误的/tmp/.npm
权限上。
drwxr-xr-x 114 root root 4.0K Dec 27 17:04 .npm
这很令人困惑,因为我期望一个简单的“npm install”命令可以直接运行。更新:应该注意到项目目录已经包含一个“node_modules”文件夹,但即使删除它并运行“npm install”,问题也无法解决。
sudo /opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/node /opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/npm install
- Sbbs