aws-amplify / aws-amplify/amplify-hosting
NextJS: Build fails with Module not found (webpack)
- Dominant language
- Dockerfile
- Stars
- 481
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
If you are facing Webpack issues that manifests as _Module not found_ errors during your build, for example:
```
./node_modules/@prisma/client/runtime/index.js
Module not found: Can't resolve '_http_common' in '/node_modules/@prisma/client/runtime'
```
First, you should check the troubleshooting guide provided by NextJS on this issue: https://nextjs.org/docs/messages/module-not-found.
If their guide didn't help. You can reproduce these errors locally by building your app locally using the `serverless` target in your `next.config.js` file:
```js
module.exports = {
target: "serverless"
};
```
If the build fails locally with the same module not found errors. It's likely that you need to build the app using the experimental serverless trace target in your `next.config.js` file:
```js
module.exports = {
target: "experimental-serverless-trace"
};
```
If the build succeeds locally with experimental serverless trace. You can opt-in into this behavior on Amplify by setting the environment variable `AMPLIFY_NEXTJS_EXPERIMENTAL_TRACE` with a value of `true` in your App build settings.

Contributor guide
Assessment
This issue has not been assessed yet.