无法在 Elastic Beanstalk 上部署节点:命令“/bin/sh -c npm install”返回非零代码:1

Aug*_*Bar 3 docker reactjs amazon-elastic-beanstalk

我正在使用 AWS 的 Elastic beanstalk 来部署和托管使用 Docker 的 React 应用程序。

尽管我在本地计算机上成功构建了 Docker 映像,但部署却神秘地失败了。对 EC2 实例上的日志进行检查(使用eb ssh)并没有提供更多解释:

--------------------------------
/var/log/eb-commandprocessor.log
--------------------------------
Step 5/14 : COPY package.json /usr/src/app/package.json
---> Using cache
---> f06f2c9d6519
Step 6/14 : RUN npm install
---> Running in 9926fc11431f
The command '/bin/sh -c npm install' returned a non-zero code: 1
Failed to build Docker image aws_beanstalk/staging-app: 2c9d6519
Run Code Online (Sandbox Code Playgroud)

npm install我什至尝试使用以下命令在构建容器的最后一层内运行命令

sudo docker commit 9926fc11431f test && docker run -it test bash
cd /path/to/wordir
npm install 
Run Code Online (Sandbox Code Playgroud)

但返回码实际上是0

还有其他方法可能会失败并且日志返回错误的错误吗?

Dow*_*oat 5

我正在为任何未来的人写这个答案。如果没有NPM错误信息。问题是内存耗尽,在 Beanstalk 上有两种具体解决方法:

  • 使用内存更大的机器(而不是 t2.micro)
  • (推荐)切换到yarn. Yarn 使用的内存比 npm 少得多。
  • 找出其他方法来减少内存占用

这个问题让我很头疼,所以我希望这对以后遇到这个问题的人有所帮助。