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
질문됨 2년 전5325회 조회
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

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠