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",
.
Topics
Tags
asked 11 days ago10 views
1 Answers
0
Answering to myself.. Finally figured out that just removing the "type": "module"
from the package.json
fixed the issue.
answered 8 days ago
Relevant questions
AWS OpenSearch keeps dropping the indices after a failed Amplify build
asked 4 months agoCreate domain association failed One or more domains requested are already associated with another Amplify app: bakeone.in, www.bakeone.in
asked a month agoHow to host a Nuxt.js SSR app on Amplify
asked 9 months agoNextJS app fails during Amplify CI/CD deployment
asked 11 days agoApp Runner Deployment Race Condition When Using CloudFormation - No Outbound Connectivity
asked 4 months ago/api/auth/login Lambda@Edge failing with "secret" is required on AWS Amplify
asked 20 days agoAmplify won't disable SSR for non-SSR branches. How to force it to switch to SSG?
Accepted Answerasked 2 months agoAllow AWS Amplify access a restricted site for npm builds
asked 2 months agoAdding new page to NextJS app on Amplify
asked 4 months agoWildcard subdomains in AWS Amplify
Accepted Answerasked 3 years ago