Running a NextJs app from monorepo via Amplify throws 500 Internal Server Error

0

Im trying to deploy a NextJS app (Just one page /home) from a monorepo present in AWS CodeCommit via AWS Amplify. The deployment is successful and when opening the page I always get that the page is not working such that the page is currently unable to handle this request with 500 internal server error. But when I run the same in my local (either via yarn dev or yarn build followed by yarn start), I could see my app running successfully fine with no issues.

The corresponding amplify.yml file for this deployment of Next App within a monorepo is as follows

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - rm -rf node_modules && yarn install --frozen-lockfile
        build:
          commands:
            - yarn build
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: apps/staticSites

Edit: When looking into cloudwatch logs, found that there is an error log Error: Cannot find module '@swc/helpers/lib/_async_to_generator.js'. After seeing this log, I made my nextjs app to use babel instead of swc to see whether it is working now, by creating a .babelrc file in which I added below lines

{
  "presets": ["next/babel"]
}

But still seeing same log in cloudwatch. Also tried to include @swc/helpers package but still no improvements. Could anyone let me know how to overcome this issue which Im not able to replicate in my local

Error screenshot

1 Answer
0
Accepted Answer

Got the issue on why it is not working. yarn.lock was causing the issue since it already had some problems with @swc/helpers. I did a cleanup with yarn.lock by deleting the file and then it had no issues and worked perfectly fine.

So the command i used which solved the issue is - rm -rf node_modules -rf yarn.lock && yarn install --frozen-lockfile

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