我试图将带有codeship的nodejs后端部署到弹性beanstalk。但每次我收到以下错误:
bcrypt@1.0.3 install /tmp/deployment/application/node_modules/bcrypt
node-pre-gyp install --fallback-to-build
module.js:471
throw err;
^
Error: Cannot find module '../'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/tmp/deployment/application/node_modules/.bin/node-pre-gyp:15:20)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Linux 4.9.62-21.56.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.11.5-linux-x64/bin/npm" "--production" "rebuild"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! bcrypt@1.0.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@1.0.3 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs bcrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.
有谁知道如何修复它?一直试图修复它几天,非常感谢帮助!
答案 0 :(得分:4)
请尝试使用bcrypt.js
模块,而不要使用bcrypt
模块,后者是一个更新/最新的npm模块。
运行npm install bcryptjs
然后npm install
答案 1 :(得分:3)
查看此GitHub评论:https://github.com/kelektiv/node.bcrypt.js/issues/509#issuecomment-313693838
TL; DR:作为一种变通办法,在运行npm install bcrypt
之前运行npm install
答案 2 :(得分:1)
首先确保您没有上载节点模块文件夹,并且npm install命令在实例上可用。
https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions
此问题与node-pre-gyp有关。 bcrypt的依赖项。
对于AWS Elastic Beanstalk,当部署到运行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
另一种替代方法(也许是更正确的方法)是使用以下代码制作.ebextensions文件:
.ebextensions:00_change_npm_permissions.config:
"/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm
这将为您提供足够的权限来运行node-gyp
答案 3 :(得分:0)
我创建了一个 public class XmlBasedDAO {
private XMLJdbcConnection XMLJdbcConnection;
public XmlBasedDAO(XMLJdbcConnection XMLJdbcConnection) {
this.XMLJdbcConnection = XMLJdbcConnection;
}
public XMLJdbcConnection getXMLJdbcConnection() {
return XMLJdbcConnection;
}
}
文件,
.npmrc
这似乎已经做到了。
答案 4 :(得分:0)
在您的bcryptjs
中添加package.json
依赖项,然后npm install
应该可以处理所有依赖项。