aws-amplify / aws-amplify/amplify-hosting

NextJS: Build fails with Module not found (webpack)

Open
#2,427 8 comments 24 reactions 1 assignee Claimed by @ferdingler View on GitHub
documentation question
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.

![image (1)](https://user-images.githubusercontent.com/3701083/144693085-cf7868af-a110-4b99-8400-eaf2e6b18673.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.