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年前977ビュー
1回答
0

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

niobium
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ