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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则