node.js 运行节点应用程序时 bcrypt 无效的 elf 标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15809611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bcrypt invalid elf header when running node app
提问by user2244469
I'm working on a nodejs project for school. I wasn't able to install bcrypt with npm so i installed bcrypt-nodejs and the project worked fine yesterday. But today, when I do a "node app" i have this error :
我正在为学校开发一个 nodejs 项目。我无法使用 npm 安装 bcrypt,所以我安装了 bcrypt-nodejs 并且该项目昨天运行良好。但是今天,当我做一个“节点应用程序”时,我遇到了这个错误:
/.../node_modules/bcrypt/node_modules/bindings/bindings.js:79
throw e
^
Error: /.../node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/.../node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/.../node_modules/bcrypt/bcrypt.js:1:97)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
my package.json file looks like this:
我的 package.json 文件如下所示:
{
"name": "Supinfarm",
"version": "0.0.0",
"env": {
"PYTHON": "/usr/bin/python2.6"
},
"dependencies": {
"express": "3.1.0",
"connect-flash": "*",
"jade": "*",
"stylus": "*",
"passport": "*",
"passport-local": "*",
"mongoose": "*",
"bcrypt": "*"
}
}
I'm on Linux ubuntu 10.04 LTS I've tried to find a solution on google without success... Can somebody help me?
我使用的是 Linux ubuntu 10.04 LTS 我试图在谷歌上找到解决方案但没有成功......有人可以帮助我吗?
回答by Cmag
I've found that bcrypt compiled on OSX will not quite work on Linux. In other words, if you check in the bcrypt compiled on your local OSX workstation, and try to run the node app on your linux servers, you will see the error above.
我发现在 OSX 上编译的 bcrypt 在 Linux 上不太适用。换句话说,如果您签入在本地 OSX 工作站上编译的 bcrypt,并尝试在您的 linux 服务器上运行 node 应用程序,您将看到上面的错误。
Solution: npm install bcrypton Linux, check that in, solved.
解决方案:npm install bcrypt在Linux上,检查,解决。
Probably the best way to deal with this is exclude your node_modules in .gitignore... and npm install remotely.
处理这个问题的最好方法可能是在 .gitignore 中排除您的 node_modules... 并远程安装 npm。
回答by TacoEater
If you are running inside a docker container as I am, all you need is a .dockerignore with 'node_modules' specified in it.
如果您像我一样在 docker 容器中运行,那么您只需要一个 .dockerignore 并在其中指定了“node_modules”。
Some libraries need to be compiled on the host machine and therefore your modules can be stale.
某些库需要在主机上编译,因此您的模块可能已经过时。
回答by rrt
I was also facing the same issue with bcrypt v.1.0.3. Just updated to the latest version (3.0.1) and its working fine now
我也遇到了 bcrypt v.1.0.3 的同样问题。刚刚更新到最新版本(3.0.1),现在工作正常
Run
跑
npm install bcrypt@latest --save
回答by Nick
My issue was with my docker-compose.yml file, I already had node_modules in my .dockerignore but I also needed to add the node_modules directory as a volume:
我的问题是我的 docker-compose.yml 文件,我的 .dockerignore 中已经有 node_modules 但我还需要将 node_modules 目录添加为一个卷:
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
回答by Carlos Beltran
For those deploying an app to AWS elastic beanstalk, and gonna install bcrypt on the server, include in a post deploy hook in .ebextensions/01_build.config:
对于那些将应用程序部署到 AWS elastic beanstalk 并要在服务器上安装 bcrypt 的人,请将其包含在部署后挂钩中.ebextensions/01_build.config:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_build_app.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
cd /var/app/current/
rm -rf node_modules/bcrypt
sudo /opt/elasticbeanstalk/node-install/node-v10.13.0-linux-x64/bin/npm install bcrypt@latest

