NextJS app fails during Amplify CI/CD deployment

0

I have a NextJS app that uses SSR. Therefore manual deployment is not an option.

I have setup Amplify hosting for the app. Deployment (initiated by GitHub push) fails due:

Must use import to load ES Module: /codebuild/output/.../src/aws-exports.js
                                 require() of ES modules is not supported.
                                 require() of /codebuild/output/src531993483/src/myidtoken/src/aws-exports.js from /snapshot/repo/build/node_modules/amplify-frontend-javascript/lib/frontend-config-creator.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
                                 Instead rename aws-exports.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /codebuild/output/src531993483/src/myidtoken/package.json.
2022-05-10T13:24:35.567Z [INFO]: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /codebuild/output/src531993483/src/myidtoken/src/aws-exports.js
                                 require() of ES modules is not supported.
                                 require() of /codebuild/output/src531993483/src/myidtoken/src/aws-exports.js from /snapshot/repo/build/node_modules/amplify-frontend-javascript/lib/frontend-config-creator.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
                                 Instead rename aws-exports.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /codebuild/output/src531993483/src/myidtoken/package.json.

I do not have aws-exports.js committed to GitHub. So aws-exports.js is generated during the build/deploy. Therefore I cannot rename it to .csj.

I have tried though creating my-aws-exports.js and include that from my code. However, the error is still the same. This also sounds to me that the error is in generated code.

Repository is not unfortunately public so I cannot share it. I'm using

  • react 17
  • next 12
  • aws-amplify 4.3.21
  • aws-sdk 2.1131.0

package.json states "type": "module",.

niobium
질문됨 2년 전1166회 조회
1개 답변
0

Answering to myself.. Finally figured out that just removing the "type": "module" from the package.json fixed the issue.

niobium
답변함 2년 전

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

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

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

관련 콘텐츠