Home
Support Forums

Deployment failed due to a web pack build fail

Site Name: confident-tesla-fdfacd
Stack: NextJS with ExpressJS backend

I have relentlessly tried to deploy my app to Netlify, however, I am continuously met with the following build error:

My app works perfectly fine in my local environment as does building my app so I am completely perplexed by what is causing this error. Any help in resolving this error is graciously appreciated.

12:39:42 PM: Build ready to start
12:39:44 PM: build-image version: fa439ad1ab9393b2c0d449d8d7c033927683f4b0
12:39:44 PM: build-image tag: v4.3.0
12:39:44 PM: buildbot version: d8696ebd1839fd039956b1b6dd4091c4e06ce743
12:39:45 PM: Fetching cached dependencies
12:39:45 PM: Failed to fetch cache, continuing with build
12:39:45 PM: Starting to prepare the repo for build
12:39:45 PM: No cached dependencies found. Cloning fresh repo
12:39:45 PM: git clone https://github.com/sharif51693/nextjs-express-demo-master
12:39:49 PM: Preparing Git Reference refs/heads/main
12:39:51 PM: Parsing package.json dependencies
12:39:52 PM: Starting build script
12:39:52 PM: Installing dependencies
12:39:52 PM: Python version set to 2.7
12:39:53 PM: Downloading and installing node v16.7.0...
12:39:53 PM: Downloading https://nodejs.org/dist/v16.7.0/node-v16.7.0-linux-x64.tar.xz...
12:39:53 PM: Computing checksum with sha256sum
12:39:54 PM: Checksums matched!
12:39:57 PM: Now using node v16.7.0 (npm v7.20.3)
12:39:57 PM: Started restoring cached build plugins
12:39:57 PM: Finished restoring cached build plugins
12:39:57 PM: Attempting ruby version 2.7.2, read from environment
12:39:59 PM: Using ruby version 2.7.2
12:39:59 PM: Using PHP version 8.0
12:39:59 PM: Started restoring cached node modules
12:40:00 PM: Finished restoring cached node modules
12:40:00 PM: Installing NPM modules using NPM version 7.20.3
12:40:12 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
12:40:12 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
12:40:16 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
12:40:16 PM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
12:40:17 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
12:40:30 PM: npm WARN deprecated now@21.0.1: "now" is deprecated and will stop receiving updates on December 31, 2020. Please use "vercel" instead.
12:40:40 PM: added 1257 packages, and audited 1258 packages in 39s
12:40:40 PM: 110 packages are looking for funding
12:40:40 PM:   run `npm fund` for details
12:40:40 PM: 18 vulnerabilities (4 low, 14 moderate)
12:40:40 PM: To address issues that do not require attention, run:
12:40:40 PM:   npm audit fix
12:40:40 PM: To address all issues possible (including breaking changes), run:
12:40:40 PM:   npm audit fix --force
12:40:40 PM: Some issues need review, and may require choosing
12:40:40 PM: a different dependency.
12:40:40 PM: Run `npm audit` for details.
12:40:40 PM: NPM modules installed
12:40:40 PM: Started restoring cached go cache
12:40:40 PM: Finished restoring cached go cache
12:40:40 PM: go version go1.16.5 linux/amd64
12:40:40 PM: go version go1.16.5 linux/amd64
12:40:40 PM: Installing missing commands
12:40:40 PM: Verify run directory
12:40:42 PM: ​
12:40:42 PM: ────────────────────────────────────────────────────────────────
12:40:42 PM:   Netlify Build                                                 
12:40:42 PM: ────────────────────────────────────────────────────────────────
12:40:42 PM: ​
12:40:42 PM: ❯ Version
12:40:42 PM:   @netlify/build 18.4.2
12:40:42 PM: ​
12:40:42 PM: ❯ Flags
12:40:42 PM:   baseRelDir: true
12:40:42 PM:   buildId: 612520ce3b5b665b894a95b2
12:40:42 PM:   deployId: 612520ce3b5b665b894a95b4
12:40:42 PM: ​
12:40:42 PM: ❯ Current directory
12:40:42 PM:   /opt/build/repo
12:40:42 PM: ​
12:40:42 PM: ❯ Config file
12:40:42 PM:   No config file was defined: using default values.
12:40:42 PM: ​
12:40:42 PM: ❯ Context
12:40:42 PM:   production
12:40:42 PM: ​
12:40:42 PM: ❯ Installing plugins
12:40:42 PM:    - @netlify/plugin-nextjs@3.8.0
12:41:18 PM: ​
12:41:18 PM: ❯ Loading plugins
12:41:18 PM:    - @netlify/plugin-nextjs@3.8.0 from Netlify app
12:41:18 PM: ​
12:41:18 PM: ────────────────────────────────────────────────────────────────
12:41:18 PM:   1. onPreBuild command from @netlify/plugin-nextjs             
12:41:18 PM: ────────────────────────────────────────────────────────────────
12:41:18 PM: ​
12:41:18 PM: Using Next.js 11.0.1
12:41:19 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
12:41:19 PM: The "target" config property must be one of "serverless", "experimental-serverless-trace". Building with "serverless" target.
12:41:19 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
12:41:19 PM: No Next.js cache to restore.
12:41:19 PM: ​
12:41:19 PM: (@netlify/plugin-nextjs onPreBuild completed in 1s)
12:41:19 PM: ​
12:41:19 PM: ────────────────────────────────────────────────────────────────
12:41:19 PM:   2. Build command from Netlify app                             
12:41:19 PM: ────────────────────────────────────────────────────────────────
12:41:19 PM: ​
12:41:19 PM: $ npm run build
12:41:20 PM: > nextjs-express@1.0.0 build
12:41:20 PM: > next build
12:41:21 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
12:41:21 PM: info  - Checking validity of types...
12:41:22 PM: warn  - No ESLint configuration detected. Run next lint to begin setup
12:41:22 PM: info  - Creating an optimized production build...
12:41:39 PM: (node:1680) [DEP_WEBPACK_MODULE_UPDATE_HASH] DeprecationWarning: Module.updateHash: Use new ChunkGraph API
12:41:39 PM: (Use `node --trace-deprecation ...` to show where the warning was created)
12:42:14 PM: Failed to compile.
12:42:14 PM: 
12:42:14 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'bson-ext' in '/opt/build/repo/node_modules/mongodb/lib'
12:42:14 PM: > Build error occurred
12:42:14 PM: Error: > Build failed because of webpack errors
12:42:14 PM:     at /opt/build/repo/node_modules/next/dist/build/index.js:15:924
12:42:14 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:6:584)
12:42:14 PM: ​
12:42:14 PM: ────────────────────────────────────────────────────────────────
12:42:14 PM:   "build.command" failed                                        
12:42:14 PM: ────────────────────────────────────────────────────────────────
12:42:14 PM: ​
12:42:14 PM:   Error message
12:42:14 PM:   Command failed with exit code 1: npm run build
12:42:14 PM: ​
12:42:14 PM:   Error location
12:42:14 PM:   In Build command from Netlify app:
12:42:14 PM:   npm run build
12:42:14 PM: ​
12:42:14 PM:   Resolved config
12:42:14 PM:   build:
12:42:14 PM:     command: npm run build
12:42:14 PM:     commandOrigin: ui
12:42:14 PM:     publish: /opt/build/repo/out
12:42:14 PM:     publishOrigin: ui
12:42:14 PM:   plugins:
12:42:14 PM:     - inputs: {}
12:42:14 PM:       origin: ui
12:42:14 PM:       package: '@netlify/plugin-nextjs'
12:42:15 PM: Caching artifacts
12:42:15 PM: Started saving node modules
12:42:15 PM: Finished saving node modules
12:42:15 PM: Started saving build plugins
12:42:15 PM: Finished saving build plugins
12:42:15 PM: Started saving pip cache
12:42:15 PM: Finished saving pip cache
12:42:15 PM: Started saving emacs cask dependencies
12:42:15 PM: Finished saving emacs cask dependencies
12:42:15 PM: Started saving maven dependencies
12:42:15 PM: Finished saving maven dependencies
12:42:15 PM: Started saving boot dependencies
12:42:15 PM: Finished saving boot dependencies
12:42:15 PM: Started saving rust rustup cache
12:42:15 PM: Finished saving rust rustup cache
12:42:15 PM: Started saving go dependencies
12:42:15 PM: Finished saving go dependencies
12:42:17 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:42:17 PM: Creating deploy upload records
12:42:18 PM: Failing build: Failed to build site
12:42:18 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:42:18 PM: Finished processing build request in 2m33.225465556s

Can you link the repo?

Sure, please see below:

Hi @sharif25,

Could you create another repo without the node_modules, .next, package-lock.json and .DS_Store files? Those files should exist in the .gitignore of the repo.

Done. Please use this repository:

Hi @sharif25,

The repos don’t seem to exist.