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
asked 2 years ago5271 views
3 Answers
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
answered 2 years ago
0
Accepted Answer

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.

answered 2 years ago
  • 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

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions