我正在致力于将项目从 Heroku 迁移到 AWS。部署后我不断收到错误消息:“无效的 ELF 标头”。我在使用 AWS Lambda 时发现了类似问题的帖子,但我不明白为什么 Elastic Beanstalk 中的二进制包会出现问题。
Elastic Beanstalk 是否提供了类似于 Docker 的已配置环境来运行我的代码?我觉得这个问题一定更复杂,因为我在 Elastic Beanstalk 中找不到其他人遇到这个问题。
这是我收到的确切错误:
Error: /var/app/current/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/var/app/current/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] /cdn-cgi/l/email-protection start: `node server/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] /cdn-cgi/l/email-protection start 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-04-15T00_54_06_983Z-debug.log
我在 Mac 上工作,我的代码包含用 React、node.js 和 SQL 编写的客户端和服务器代码。我通过包含多个文件夹的 ZIP 文件上传我的代码,包括node_modules/
.
有些库对构建它们的操作系统和/或 CPU 架构很敏感。对于用低级语言实现的模块或链接到系统库的模块尤其如此。在这种情况下,您似乎正在使用bcrypt https://www.npmjs.com/package/bcrypt这是大部分是用 C++ 编写的 https://github.com/kelektiv/node.bcrypt.js.
这是您上传到 Elastic Beanstalk 的 zip 文件不应包含您的node_modules/
文件夹(或 Git 忽略的任何其他内容)。创建 zip 以上传到 Elastic Beanstalk 的最简单方法是可能会使用git archive https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html#using-features.deployment.source.git:
git archive -v -o myapp.zip --format=zip HEAD
这会尊重你的忽略,而手动压缩 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html#using-features.deployment.source.commandline将包括他们。
您的存档应包括package.json
and package-lock.json
于其根。弹性豆茎将安装自己的node_modules/从这些文件中 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-packagejson.html如果他们在场的话。这应该确保所有库都与其操作系统兼容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)