- Newest
- Most votes
- Most comments
This issue you're experiencing with AWS Amplify and Next.js is indeed unexpected behavior. In a standalone build of a Next.js application, the environment variables should be read from the build output folder, not from the source root.
For Next.js applications in standalone mode, the build process typically generates a standalone folder within the .next directory. This folder contains a complete, self-contained version of your application, including all necessary files and configurations. The .env.production file in this standalone folder should be the one used when running the application, not the one in the source root.
The fact that Amplify is referencing the .env.production file from the incorrect path (the source root instead of the build output folder) suggests there might be an issue with how Amplify is configured to run your Next.js application in standalone mode.
To address this, you could try the following:
-
Review your amplify.yml configuration file. Ensure that you're explicitly specifying the path to the standalone build output when starting your Next.js application.
-
You might need to adjust your build commands or artifacts configuration in the amplify.yml file to ensure that Amplify is using the correct directory structure for your standalone build.
-
Consider adding a step in your build process that copies the modified .env.production file to the correct location in the standalone build folder, overwriting the automatically generated one.
-
If the issue persists, you may need to reach out to AWS support or check the Amplify GitHub issues for any known problems related to standalone Next.js builds.
Remember, when using monorepo structures or non-standard project layouts with Amplify, extra care may be needed to ensure all paths and configurations are correctly specified.
Sources
Build container ran out of memory | AWS re:Post
AWS Amplify Resources - Amazon Web Services
Relevant content
- asked 2 years ago
- asked 5 months ago
- AWS OFFICIALUpdated 3 years ago