Build failed because of webpack errors (Next.js + AWS Amplify)

Hi,

I’m working on a Next.js + AWS Amplify project, but I can’t get it deployed :frowning: I did quite a few researches online but I haven’t found a solution to my problem.

This is the whole build log:

3:24:40 AM: Build ready to start
3:24:42 AM: build-image version: be42e453d6c8f171cc2f654acc29c0a8b60e6d93
3:24:42 AM: build-image tag: v3.7.1
3:24:42 AM: buildbot version: 94f1b7736437a080e02c046e77c9a098022fec84
3:24:42 AM: Fetching cached dependencies
3:24:42 AM: Failed to fetch cache, continuing with build
3:24:42 AM: Starting to prepare the repo for build
3:24:42 AM: No cached dependencies found. Cloning fresh repo
3:24:42 AM: git clone git@gitlab.com:siteme-ch/ohm
3:24:44 AM: Preparing Git Reference refs/heads/develop
3:24:45 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘out’ versus ‘out/’ in the Netlify UI
3:24:46 AM: Starting build script
3:24:46 AM: Installing dependencies
3:24:46 AM: Python version set to 2.7
3:24:47 AM: v12.18.0 is already installed.
3:24:48 AM: Now using node v12.18.0 (npm v6.14.4)
3:24:48 AM: Started restoring cached build plugins
3:24:48 AM: Finished restoring cached build plugins
3:24:48 AM: Attempting ruby version 2.7.1, read from environment
3:24:49 AM: Using ruby version 2.7.1
3:24:49 AM: Using PHP version 5.6
3:24:49 AM: Started restoring cached yarn cache
3:24:49 AM: Finished restoring cached yarn cache
3:24:49 AM: Installing yarn at version 1.22.4
3:24:49 AM: Installing Yarn!
3:24:49 AM: > Downloading tarball…
3:24:49 AM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz → /tmp/yarn.tar.gz.YmaeSTR6Nl
3:24:49 AM: % Total % Received % Xferd Average Speed Time Time Time Current
3:24:49 AM: Dload Upload Total Spent Left Speed
3:24:50 AM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
3:24:50 AM: 100 79 100 79 0 0 324 0 --:–:-- --:–:-- --:–:-- 325
3:24:50 AM: 100 93 100 93 0 0 186 0 --:–:-- --:–:-- --:–:-- 186
3:24:51 AM: 0 0 0 0 0 0 0 0 --:–:-- 0:00:01 --:–:-- 0
3:24:51 AM: 100 625 100 625 0 0 483 0 0:00:01 0:00:01 --:–:-- 2500
3:24:51 AM: 100 1215k 100 1215k 0 0 711k 0 0:00:01 0:00:01 --:–:-- 711k
3:24:51 AM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc → /tmp/yarn.tar.gz.YmaeSTR6Nl.asc
3:24:51 AM: 100 83 100 83 0 0 1522 0 --:–:-- --:–:-- --:–:-- 1522
3:24:51 AM: 100 97 100 97 0 0 1181 0 --:–:-- --:–:-- --:–:-- 1181
3:24:51 AM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
3:24:51 AM: 100 629 100 629 0 0 1878 0 --:–:-- --:–:-- --:–:-- 614k
3:24:52 AM: 100 1028 100 1028 0 0 2676 0 --:–:-- --:–:-- --:–:-- 2676
3:24:52 AM: > Verifying integrity…
3:24:52 AM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
3:24:52 AM: gpg: Good signature from “Yarn Packaging yarn@dan.cx
3:24:52 AM: gpg: WARNING: This key is not certified with a trusted signature!
3:24:52 AM: gpg: There is no indication that the signature belongs to the owner.
3:24:52 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
3:24:52 AM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
3:24:52 AM: > GPG signature looks good
3:24:52 AM: > Extracting to ~/.yarn…
3:24:52 AM: > Adding to $PATH…
3:24:52 AM: > Successfully installed Yarn 1.22.4! Please open another terminal where the yarn command will now be available.
3:24:52 AM: Started restoring cached node modules
3:24:52 AM: Finished restoring cached node modules
3:24:52 AM: Installing NPM modules using Yarn version 1.22.4
3:24:53 AM: yarn install v1.22.4
3:24:53 AM: [1/4] Resolving packages…
3:24:54 AM: [2/4] Fetching packages…
3:25:20 AM: info fsevents@2.1.3: The platform “linux” is incompatible with this module.
3:25:20 AM: info “fsevents@2.1.3” is an optional dependency and failed compatibility check. Excluding it from installation.
3:25:20 AM: info fsevents@2.3.2: The platform “linux” is incompatible with this module.
3:25:20 AM: info “fsevents@2.3.2” is an optional dependency and failed compatibility check. Excluding it from installation.
3:25:20 AM: info fsevents@1.2.13: The platform “linux” is incompatible with this module.
3:25:20 AM: info “fsevents@1.2.13” is an optional dependency and failed compatibility check. Excluding it from installation.
3:25:20 AM: [3/4] Linking dependencies…
3:25:20 AM: warning “aws-amplify > @aws-amplify/analytics > @aws-sdk/client-firehose > @aws-sdk/middleware-retry > react-native-get-random-values@1.6.0” has unmet peer dependency “react-native@>=0.56”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/analytics@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/api@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/auth@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/core@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/interactions@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/storage@3.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/ui@2.x.x”.
3:25:20 AM: warning " > aws-amplify-react@4.2.30" has unmet peer dependency “@aws-amplify/xr@2.x.x”.
3:25:20 AM: warning “aws-amplify-react > qrcode.react@0.8.0” has incorrect peer dependency “react@^15.5.3 || ^16.0.0”.
3:25:20 AM: warning " > next-images@1.7.0" has unmet peer dependency “webpack@^4.0.0 || ^5.0.0”.
3:25:20 AM: warning “next-images > file-loader@6.2.0” has unmet peer dependency “webpack@^4.0.0 || ^5.0.0”.
3:25:20 AM: warning “next-images > url-loader@4.1.1” has unmet peer dependency “webpack@^4.0.0 || ^5.0.0”.
3:25:20 AM: warning " > react-text-truncate@0.16.0" has incorrect peer dependency “react@^15.4.1 || ^16.0.0”.
3:25:20 AM: warning " > react-text-truncate@0.16.0" has incorrect peer dependency “react-dom@^15.4.1 || ^16.0.0”.
3:25:20 AM: warning " > styled-components@5.2.3" has unmet peer dependency “react-is@>= 16.8.0”.
3:25:20 AM: warning “@storybook/addon-actions > react-inspector@5.1.0” has incorrect peer dependency “react@^16.8.4”.
3:25:20 AM: warning “@storybook/addon-actions > @storybook/api > @reach/router@1.3.4” has incorrect peer dependency “react@15.x || 16.x || 16.4.0-alpha.0911da3”.
3:25:20 AM: warning “@storybook/addon-actions > @storybook/api > @reach/router@1.3.4” has incorrect peer dependency “react-dom@15.x || 16.x || 16.4.0-alpha.0911da3”.
3:25:20 AM: warning “@storybook/addon-actions > @storybook/api > @reach/router > create-react-context@0.3.0” has incorrect peer dependency “react@^0.14.0 || ^15.0.0 || ^16.0.0”.
3:25:20 AM: warning " > babel-loader@8.2.2" has unmet peer dependency “webpack@>=2”.
3:25:20 AM: warning “@storybook/addon-essentials > @storybook/addon-docs > @storybook/core > @storybook/core-client@6.2.7” has unmet peer dependency “webpack@*”.
3:25:35 AM: [4/4] Building fresh packages…
3:25:40 AM: Done in 46.91s.
3:25:40 AM: NPM modules installed using Yarn
3:25:40 AM: Started restoring cached go cache
3:25:40 AM: Finished restoring cached go cache
3:25:40 AM: go version go1.14.4 linux/amd64
3:25:40 AM: go version go1.14.4 linux/amd64
3:25:40 AM: Installing missing commands
3:25:40 AM: Verify run directory
3:25:41 AM: ​
3:25:41 AM: ────────────────────────────────────────────────────────────────
3:25:41 AM: Netlify Build
3:25:41 AM: ────────────────────────────────────────────────────────────────
3:25:41 AM: ​
3:25:41 AM: ❯ Version
3:25:41 AM: @netlify/build 10.2.7
3:25:41 AM: ​
3:25:41 AM: ❯ Flags
3:25:41 AM: deployId: 6073a158ca631c9ef29b12b6
3:25:42 AM: ​
3:25:42 AM: ❯ Current directory
3:25:42 AM: /opt/build/repo
3:25:42 AM: ​
3:25:42 AM: ❯ Config file
3:25:42 AM: No config file was defined: using default values.
3:25:42 AM: ​
3:25:42 AM: ❯ Context
3:25:42 AM: production
3:25:42 AM: ​
3:25:42 AM: ❯ Installing plugins
3:25:42 AM: - @netlify/plugin-nextjs@1.1.3
3:26:05 AM: ​
3:26:05 AM: ❯ Loading plugins
3:26:05 AM: - @netlify/plugin-nextjs@1.1.3 from Netlify app
3:26:05 AM: ​
3:26:05 AM: ❯ Outdated plugins
3:26:05 AM: - @netlify/plugin-nextjs@1.1.3: latest version is 3.0.3 which is incompatible with next@<10.0.6
3:26:06 AM: ​
3:26:06 AM: ────────────────────────────────────────────────────────────────
3:26:06 AM: 1. onPreBuild command from @netlify/plugin-nextjs
3:26:06 AM: ────────────────────────────────────────────────────────────────
3:26:06 AM: ​
3:26:06 AM: ** Warning: support for Next.js >=10.0.0 is experimental **
3:26:06 AM: Your next.config.js must set the “target” property to one of: serverless, experimental-serverless-trace. Update the
3:26:06 AM: target property to allow this plugin to run.
3:26:06 AM: ​
3:26:06 AM: (@netlify/plugin-nextjs onPreBuild completed in 30ms)
3:26:06 AM: ​
3:26:06 AM: ────────────────────────────────────────────────────────────────
3:26:06 AM: 2. Build command from Netlify app
3:26:06 AM: ────────────────────────────────────────────────────────────────
3:26:06 AM: ​
3:26:06 AM: $ yarn build
3:26:06 AM: yarn run v1.22.4
3:26:06 AM: $ next build
3:26:07 AM: Browserslist: caniuse-lite is outdated. Please run:
3:26:07 AM: npx browserslist@latest --update-db
3:26:07 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
3:26:07 AM: info - Creating an optimized production build…
3:26:17 AM: info - Using external babel configuration from /opt/build/repo/.babelrc
3:26:20 AM: Failed to compile.
3:26:20 AM:
3:26:20 AM: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘…/src/aws-exports’ in ‘/opt/build/repo/pages’
3:26:20 AM: > Build error occurred
3:26:20 AM: Error: > Build failed because of webpack errors
3:26:20 AM: at /opt/build/repo/node_modules/next/dist/build/index.js:15:918
3:26:20 AM: at runMicrotasks ()
3:26:20 AM: at processTicksAndRejections (internal/process/task_queues.js:97:5)
3:26:20 AM: at async /opt/build/repo/node_modules/next/dist/build/tracer.js:1:525
3:26:20 AM: error Command failed with exit code 1.
3:26:20 AM: info Visit yarn run | Yarn for documentation about this command.
3:26:20 AM: ​
3:26:20 AM: ────────────────────────────────────────────────────────────────
3:26:20 AM: “build.command” failed
3:26:20 AM: ────────────────────────────────────────────────────────────────
3:26:20 AM: ​
3:26:20 AM: Error message
3:26:20 AM: Command failed with exit code 1: yarn build
3:26:20 AM: ​
3:26:20 AM: Error location
3:26:20 AM: In Build command from Netlify app:
3:26:20 AM: yarn build
3:26:20 AM: ​
3:26:20 AM: Resolved config
3:26:20 AM: build:
3:26:20 AM: command: yarn build
3:26:20 AM: commandOrigin: ui
3:26:20 AM: publish: /opt/build/repo/out
3:26:20 AM: plugins:
3:26:20 AM: - inputs: {}
3:26:20 AM: origin: ui
3:26:20 AM: package: ‘@netlify/plugin-nextjs’
3:26:21 AM: Caching artifacts
3:26:21 AM: Started saving node modules
3:26:21 AM: Finished saving node modules
3:26:21 AM: Started saving build plugins
3:26:21 AM: Finished saving build plugins
3:26:21 AM: Started saving yarn cache
3:26:21 AM: Finished saving yarn cache
3:26:21 AM: Started saving pip cache
3:26:21 AM: Finished saving pip cache
3:26:21 AM: Started saving emacs cask dependencies
3:26:21 AM: Finished saving emacs cask dependencies
3:26:21 AM: Started saving maven dependencies
3:26:21 AM: Finished saving maven dependencies
3:26:21 AM: Started saving boot dependencies
3:26:21 AM: Finished saving boot dependencies
3:26:21 AM: Started saving rust rustup cache
3:26:21 AM: Finished saving rust rustup cache
3:26:21 AM: Started saving go dependencies
3:26:21 AM: Finished saving go dependencies
3:26:24 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:26:24 AM: Creating deploy upload records
3:26:24 AM: Failing build: Failed to build site
3:26:24 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
3:26:24 AM: Finished processing build request in 1m42.099029769s

i don’t understand if I’m doing something wrong with Amplify (I have followed their guide and I don’t see anything wrong in my code), or if it’s something else.

Any ideas/suggestions/support would be really appreciated :cry:

Cheers,
Dave

Either this module doesn’t exist in your repo or the case of the filename is different than the one used in import statement.

Hi, I’m facing the same issue.

ModuleNotFoundError: Module not found: Error: Can't resolve './../components/ui/common/Faqs' in '/codebuild/output/src675342249/src/anh.pw/pages'

I do understand the error message but… i check the path (with the case of filename) and everything but can not find any thing wrong.

Please note that… local build is successfully and I use VSCode, double checked… still can not figure out why.

Do you have any idea to check?!

Thank you so much!

Rgds

Solved!

Just read a comment from this next.js - nextJS build fails on Vercel because of Webpack errors - Stack Overflow

Solution:

it seems that even though my local components are Capitalized the remote branch had some components lowercased.

A solution was also listed here:

1 Like