带有依赖项node-pre-gyp的Bcrypt在部署到Elastic Beanstalk时会引起一些严重的问题。
bcrypt版本:3.0.6
Nodejs版本:8.16(对于v.10也相同)
Amazon Linux 4.8.2
bcrypt@3.0.6 install /tmp/deployment/application/node_modules/bcrypt
node-pre-gyp install --fallback-to-build
module.js:550
throw err;
^
Error: Cannot find module '../'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/tmp/deployment/application/node_modules/.bin/node-pre-gyp:15:20)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@3.0.6 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@3.0.6 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/2019-08-11T14_06_34_179Z-debug.log
Running npm install: /opt/elasticbeanstalk/node-install/node-v8.15.1-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 2019/08/11 14:06:34 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log
package.json的相关部分
"dependencies": {
"axios": "^0.19.0",
"bcrypt": "^3.0.6",
"body-parser": "^1.18.3",
"chai": "^4.2.0",
"express": "^4.16.4",
"firebase": "^5.8.6",
"firebase-admin": "~6.0.0",
"jsonwebtoken": "^8.5.0",
"mocha": "^6.0.2",
"shortid": "^2.2.14"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.4",
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
答案 0 :(得分:2)
当部署到运行Node 8.x的Elastic Beanstalk时,node-gyp没有足够的权限写入tmp目录。 bcrypt无法安装,并且应用程序部署将失败。
一种解决方法是将.npmrc文件添加到项目的根目录,这将强制node-gyp以root身份运行并允许安装完成。 .npmrc的文件内容:
# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5 or @6
unsafe-perm=true
请同时https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions对此进行检查
信用转到此职位: Beanstalk: Node.js deployment - node-gyp fails due to permission denied