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
gefragt vor 2 Jahren1166 Aufrufe
1 Antwort
0

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

niobium
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen