我正在尝试将NodeJS应用程序上传到Amazon AWS中的Elastic Beanstalk。但是,当执行npm install时,它会引起一些权限被拒绝,因此无法运行该应用程序。这是日志
var payload = {
notification:{
title: "New message!",
body: "Tab to read it!",
sound: "default",
click_action: "OPENNOTIFICATION",
icon: "rateiconsari"
}
};
if(sdknumber <= 26) {
payload.icon = "logo2";
}
我一直在寻找一些解决方案,但没人能解决。我还将此脚本添加到.ebextensions / 00_change_npm_permissions.config中,以添加root权限,但没有任何效果。
Application update failed at 2018-10-02T15:18:14Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed.
+ /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN deprecated tar.gz@1.0.7: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise Support
> scrypt@6.0.3 preinstall /tmp/deployment/application/node_modules/scrypt
> node node-scrypt-preinstall.js
Error: Error: Command failed: ./configure
./configure: line 1904: config.log: Permission denied
./configure: line 1914: config.log: Permission denied
> keccak@1.4.0 install /tmp/deployment/application/node_modules/keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."
> keccak@1.4.0 rebuild /tmp/deployment/application/node_modules/keccak
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/keccak/build'
gyp ERR! System Linux 4.14.67-66.56.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/keccak
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keccak@1.4.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keccak@1.4.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
┌──────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /tmp/.config │
└──────────────────────────────────────────────────┘
Keccak bindings compilation fail. Pure JS implementation will be used.
> scrypt@6.0.3 install /tmp/deployment/application/node_modules/scrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/scrypt/build'
gyp ERR! System Linux 4.14.67-66.56.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/scrypt
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN cryptocms@0.1.0 No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt@6.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2018-10-02T15_18_14_229Z-debug.log
Running npm install: /opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
UTC 2018/10/02 15:18:14 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log
Traceback (most recent call last):
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in <module>
main()
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 677, in main
node_version_manager.run_npm_install(options.app_path)
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 136, in run_npm_install
self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
raise e
subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1.
Incorrect application version "nodecms_0.1.0" (deployment 3). Expected version "nodecms-0.1.0" (deployment 1).
我是Amazon AWS的新手,希望有人可以帮助我解决此问题。
我也尝试将具有unsafe-perm = true的.npmrc文件放入NodeJS项目的根目录(如此处所述:Beanstalk: Node.js deployment - node-gyp fails due to permission denied),但问题仍然存在
答案 0 :(得分:1)
因此,在尝试了所有方法之后,唯一可行的解决方案是在Beanstalk控制台中添加环境属性:
NPM_CONFIG_UNSAFE_PERM = true
结合我先前的尝试,EC2终于能够部署我的NodeJS项目。