【问题标题】:AWS Elastic Beanstalk invalid binary packagesAWS Elastic Beanstalk 无效的二进制包
【发布时间】:2019-04-24 00:17:22
【问题描述】:

我正在将一个项目从 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! beer@0.1.0 start: `node server/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the beer@0.1.0 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/

【问题讨论】:

  • 您是否有多个node_modules/ 文件夹,例如一个用于您的前端,另一个用于您的后端?
  • @Chris 我只有一个 node_modules 文件夹,但是里面有很多子文件夹。

标签: amazon-web-services heroku amazon-elastic-beanstalk


【解决方案1】:

某些库对构建它们的操作系统和/或 CPU 架构很敏感。对于以低级语言实现的模块或链接到系统库的模块尤其如此。在这种情况下,您似乎使用的是bcrypt,即largely written in C++

这是您上传到 Elastic Beanstalk 的 zip 文件不应包含您的 node_modules/ 文件夹(或 Git 忽略的任何其他内容)的原因之一。创建用于上传到 Elastic Beanstalk 的 zip 的最简单方法是 probably to use git archive

 git archive -v -o myapp.zip --format=zip HEAD

这将尊重您的忽略,而manually zipping 将包括它们。

您的存档应在其根目录中包含package.jsonpackage-lock.json。 Elastic Beanstalk will install its own node_modules/ from these files(如果存在)。这应该确保所有库都与其操作系统兼容。

【讨论】:

  • 谢谢克里斯,这看起来可以解决我的问题。你知道为什么 Heroku 在我上传代码时会忽略 node_modules 吗?
  • 并不是忽略那个目录。这是因为某些模块对构建它们的操作系统和/或 CPU 架构很敏感。对于用 C 等低级语言编写或链接到系统库的模块尤其如此。我怀疑您使用的是this library,即largely written in C++。我会澄清我的答案。
猜你喜欢
  • 2016-05-10
  • 2015-09-26
  • 1970-01-01
  • 2019-10-01
  • 2011-09-07
  • 2017-01-17
  • 2017-08-05
  • 2018-06-05
  • 2019-03-09
相关资源
最近更新 更多