Elastic Beanstalk npm install fails without error message

0

I am now trying for way to long to deploy a Node.js v16, npm v8 NestJS Api to AWS Elastic Beanstalk with no success. It always stops at the point where npm install is called, which fails without further explanation. The EC2 instance used is a t4g.small with AWS Linux. Those are the only information I get from the log files:

2022/04/06 12:17:27.564667 [INFO] Executing instruction: Use NPM to install dependencies
2022/04/06 12:17:27.564707 [INFO] use npm to install dependencies
2022/04/06 12:17:27.564755 [INFO] Running command /bin/sh -c npm config set jobs 1
2022/04/06 12:17:27.918363 [INFO] Running command /bin/sh -c npm --production install
2022/04/06 12:17:41.632070 [ERROR] An error occurred during execution of command [app-deploy] - [Use NPM to install dependencies]. Stop running the command. Error: Command /bin/sh -c npm --production install failed with error signal: killed 

2022/04/06 12:17:41.632467 [INFO] Executing cleanup logic
2022/04/06 12:17:41.643564 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment: 'npm' failed to install dependencies that you defined in 'package.json'. For details, see 'eb-engine.log'. The deployment failed.","timestamp":1649247461630,"severity":"ERROR"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1649247461633,"severity":"ERROR"}]}]}

2022/04/06 12:17:41.650817 [INFO] Platform Engine finished execution on command: app-deploy

The interesting part is that when I run everything in AWS CodeBuild it works flawlessly, but including node_modules the artifact is too big to upload to Elastic Beanstalks as the maximum file size seems to be 500 MB.

Does anyone know what the problem could be?

Simon
已提问 3 年前5950 查看次数
3 回答
2

There's some bug in npm v7+, it uses a lot of memory and is slower when "node_modules" doesn't exist yet. See this answer: https://github.com/npm/cli/issues/3208#issuecomment-1002990902

The solution is to create node_modules in a prebuild hook:

mkdir node_modules

and install manually in predeploy hook (elastic beanstalk will bail out of installing if node_modules already exists) predeploy:

npm install --omit=dev

Note, we need to split in 2 steps, because elasticbeanstalk installs the target node version in the middle and run npm install immediately.

pmoleri
已回答 2 年前
0
已接受的回答

I know it's too late, but anyway.

I had the same problem: the app was successfully deployed to elastic beanstalk with node v14 but failed with no adequate error while deploying to node v16.

The problem was the lack of memory. For some reason, npm v8 (which is installed with node v16) uses more memory while packages installing than npm v6 (which is installed with node v14). I haven't investigated the reason yet.

Changing the tier from 1GB RAM to 2GB RAM solved the issue.

已回答 2 年前
  • For me, it also helped to increase the build server to more RAM. The annoying part was that there is no error message or anything and I just noticed it accidentally.

0

The beanstalk node script really need to be updated to use --omit=dev

已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则