将 Node.js 应用程序( Node 6,npm 5)部署到 Beanstalk 失败:
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/heapdump/build'
虽然错误不是特定于包的,但任何 node-gyp 调用都会失败。
AWS 控制台中的 ERROR 事件显示为:
[Instance: i-12345] Command failed on instance. Return code: 1 Output: (TRUNCATED).../opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install raise e subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
和 eb-activity.log
包含上述 npm 错误。
该应用程序是通过上传一个不包含 node_modules
的 .zip 文件手动部署的。 IE。它不是通过 eb
命令行工具部署的。
最佳答案
解决方案
解决方法是将文件 .npmrc
添加到应用程序中,内容如下:
# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5
unsafe-perm=true
(或以任何其他方式配置 npm。(尽管在 /opt/elasticbeanstalk/env.vars
中设置 npm_config_unsafe_perm=true
对我不起作用。)
说明
npm install
由 root 用户运行,但它为某些包触发的 node-gyp
进程由默认用户运行 ec2-user
。此用户无法访问由 npm install 运行创建并由 root 拥有的 /tmp/deployment/application/node_modules/
目录。 (而且它可能也无法访问由它们创建的 /tmp/.npm
和 /tmp/.config
。)通过启用 unsafe-perm
我们强制 npm 以 root 身份运行 node-gyp,避免了这个问题。
(我个人更愿意以 ec2-user
而不是 root
的身份运行所有程序,但我想这会涉及更多:-))
学分
unreal0 has pointed me to the solution
相关问题
关于node.js - Beanstalk : Node. js 部署-node-gyp 由于权限被拒绝而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46001516/