Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Setting Next.js the pipeline to deploy to AWS Beanstalk

박성민 June 20, 2023

Hi folks,

I'm struggling with building pipeline for 2 days, so I really need your help this stage.

 

I've gotten a project which is written in Next.js, and I need to make a pipeline to deploy the project to AWS Beanstalk.

 

This is my pipeline below.

```


image: node:16

pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- node
script:
- npm install
- npm test
- step:
name: Code linting
script:
- npm install eslint
- npx eslint .
caches:
- node
branches:
main:
- step:
name: Build v1
caches:
- node
script:
- rm -rf node_modules
- rm -f package-lock.json
- apt-get update
- apt-get install zip
- npm install
#- npm audit fix --force
- npm run build
#- npm fund
- zip -r application.zip . -x node_modules/\* src/\* .git/\*
- ls -LR
artifacts:
- "application.zip"
- step:
name: Deploy to Production
trigger: manual
deployment: Production
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:1.1.0
variables:
AWS_ACCESS_KEY_ID: $BITBUCKET_PIPELINE_ACCESS_KEY
AWS_SECRET_ACCESS_KEY: $BITBUCKET_PIPELINE_SECRET_KEY
AWS_DEFAULT_REGION: 'ap-northeast-2'
APPLICATION_NAME: 'care-mono-app'
ENVIRONMENT_NAME: 'care-admin-client-master'
S3_BUCKET: $S3_BUCKET_DEPLOY
ZIP_FILE: 'application.zip'

```

If I run this pipeline, Beanstalk doesn't work and it puts weird error message like this.

```

Jun 21 01:58:17 ip-172-31-14-187 web: > next start

Jun 21 01:58:17 ip-172-31-14-187 web: node:internal/modules/cjs/loader:1029

Jun 21 01:58:17 ip-172-31-14-187 web: throw err;

Jun 21 01:58:17 ip-172-31-14-187 web: ^

Jun 21 01:58:17 ip-172-31-14-187 web: Error: Cannot find module '../build/output/log'

Jun 21 01:58:17 ip-172-31-14-187 web: Require stack:

Jun 21 01:58:17 ip-172-31-14-187 web: - /var/app/current/node_modules/.bin/next

Jun 21 01:58:17 ip-172-31-14-187 web: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)

Jun 21 01:58:17 ip-172-31-14-187 web: at Function.Module._load (node:internal/modules/cjs/loader:871:27)

Jun 21 01:58:17 ip-172-31-14-187 web: at Module.require (node:internal/modules/cjs/loader:1098:19)

Jun 21 01:58:17 ip-172-31-14-187 web: at require (node:internal/modules/cjs/helpers:108:18)

Jun 21 01:58:17 ip-172-31-14-187 web: at Object.<anonymous> (/var/app/current/node_modules/.bin/next:3:35)

Jun 21 01:58:17 ip-172-31-14-187 web: at Module._compile (node:internal/modules/cjs/loader:1196:14)

Jun 21 01:58:17 ip-172-31-14-187 web: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)

Jun 21 01:58:17 ip-172-31-14-187 web: at Module.load (node:internal/modules/cjs/loader:1074:32)

Jun 21 01:58:17 ip-172-31-14-187 web: at Function.Module._load (node:internal/modules/cjs/loader:909:12)

Jun 21 01:58:17 ip-172-31-14-187 web: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {

Jun 21 01:58:17 ip-172-31-14-187 web: code: 'MODULE_NOT_FOUND',

Jun 21 01:58:17 ip-172-31-14-187 web: requireStack: [ '/var/app/current/node_modules/.bin/next' ]

Jun 21 01:58:17 ip-172-31-14-187 web: }

Jun 21 03:42:18 ip-172-31-14-187 web: > unicare-admin@0.1.0 start

Jun 21 03:42:18 ip-172-31-14-187 web: > next start -p 8081

Jun 21 03:42:18 ip-172-31-14-187 web: ready - started server on 0.0.0.0:8081, url: http://localhost:8081

Jun 21 03:42:18 ip-172-31-14-187 web: info  - Loaded env from /var/app/current/.env

```

Does anyone figure out which one would be problem in this pipeline?

Or can I have a basic build and deploy script for Next.js to AWS Beanstalk?

 

Regards,

Chris

1 answer

1 accepted

0 votes
Answer accepted
박성민 June 21, 2023

This is duplicate question from https://community.atlassian.com/t5/Bitbucket-questions/Cannot-deploy-my-next-js-application-to-AWS-Beanstalk/qaq-p/2395259

I thought that I didn't publish this article when it was in moderate.

Anyway, I figured it out to rewrite my build script like below

 

script:
- rm -rf node_modules
- rm -rf package-lock.json
- apt-get update
- apt-get install zip
- npm cache clean --force
- npm install
- npm run build
- zip -r application.zip . #-x node_modules/\* src/\* .git/\*
- ls -al

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events