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
feita há 2 anos977 visualizações
1 Resposta
0

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

niobium
respondido há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas