Beanstalk:Node.js 部署 - 由于权限被拒绝,node-gyp 失败 [英] Beanstalk: Node.js deployment - node-gyp fails due to permission denied

查看:54
本文介绍了Beanstalk:Node.js 部署 - 由于权限被拒绝,node-gyp 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 Node.js 应用程序(节点 6,npm 5)部署到 Beanstalk 失败:

Deployment of a Node.js application (Node 6, npm 5) to Beanstalk fails with:

gyp 错误!堆栈错误:EACCES:权限被拒绝,mkdir'/tmp/deployment/application/node_modules/heapdump/build'

gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/heapdump/build'

虽然错误不是特定于包的,但任何 node-gyp 调用都会失败.

though the error is not package-specific, any node-gyp call fails.

AWS 控制台中的 ERROR 事件显示:

The ERROR event in the AWS Console reads:

[实例:i-12345] 命令在实例上失败.返回代码:1 输出:(截断).../opt/elasticbeanstalk/containerfiles/ebnode.py", 行180、在 npm_install 中引发 e subprocess.CalledProcessError: Command'['/opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/npm','--production', 'install']' 返回非零退出状态 1. 钩子/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh 失败.更多详细信息,请使用控制台或 EB CLI 检查/var/log/eb-activity.log.

[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 错误.

and eb-activity.log contained the aforementioned npm error.

该应用程序是通过上传不包含 node_modules 的 .zip 文件手动部署的.IE.它不是通过 eb 命令行工具部署的.

The application was deployed manually by uploading a .zip file that did not include node_modules. I.e. it was not deployed via the eb command-line tool.

推荐答案

解决方案

解决办法是将.npmrc文件添加到应用中,内容如下:

Solution

The solution is to add the file .npmrc to the application with the content:

# 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 对我不起作用.)

(Or configuring npm so in any other way. (Though setting npm_config_unsafe_perm=true in /opt/elasticbeanstalk/env.vars did not work for me.)

npm install 由 root 用户运行,但它为某些包触发的 node-gyp 进程由默认用户 ec2-user.此用户无法访问由 npm install run 创建并由 root 拥有的 /tmp/deployment/application/node_modules/ 目录.(并且它可能也无法访问由相同创建的 /tmp/.npm/tmp/.config.)通过启用 unsafe-perm 我们强制 npm 也以 root 身份运行 node-gyp,避免了这个问题.

npm install is run by the root user but the node-gyp process it triggers for some packages is run by the default user ec2-user. This user lacks access to the /tmp/deployment/application/node_modules/ directory created by the npm install run and owned by root. (And it likely also lacks access to /tmp/.npm and /tmp/.config created by the same.) By enabling unsafe-perm we force npm to run node-gyp also as root, avoiding the problem.

(我个人更喜欢以 ec2-user 而不是 root 的身份运行,但我想这会更复杂:-))

(Personally I would prefer to run all as ec2-user rather than root but I guess that would be more involved :-))

unreal0 为我指出了解决方案

这篇关于Beanstalk:Node.js 部署 - 由于权限被拒绝,node-gyp 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆