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
posta 3 anni fa5946 visualizzazioni
3 Risposte
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
con risposta 2 anni fa
0
Risposta accettata

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.

con risposta 2 anni fa
  • 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

con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande