Deployment failing due to webpack-cli issue

My site’s deployment is failing with the following error:

9:35:30 PM: One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
9:35:30 PM: - webpack-cli (GitHub - webpack/webpack-cli: Webpack's Command Line Interface)
9:35:30 PM: The original webpack full-featured CLI.
9:35:30 PM: We will use β€œnpm” to install the CLI via β€œnpm install -D”.
9:35:30 PM: Do you want to install β€˜webpack-cli’ (yes/no):

I’m running npx webpack as part of the build command and it’s causing the above error.

The exact same setup works fine on the staging branch, which has the same code and configurations, but fails on the master branch. I didn’t do anything special for the staging branch.

My package.json has both webpack and webpack-cli as dev dependencies.

What do I need to do to resolve this issue?

Thanks!

I managed to resolve the issue. I had the NODE_ENV variable set to production, which was causing the build to ignore my dev dependencies.

1 Like

i am facing the same issue but i cannot figure out what thing is goin wrong? can you please help me out with that. i have a react app with customely configured webpack and babel and workbox pwa.

Hiya, sorry you are having trouble with your build.

This Support Guide contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile: Additionally, this Support Guide houses all of our resources for debugging build and deploy issues.

We also recommend trying to search the forums with the build error you encountered - it’s likely your question was already asked by someone else!

If you are still having problems, please provide as much information as you can on what you have already tried, what your build settings are, a copy of your full deploy log (rather than just a section), your package.json / toml file, etc. Thanks!

11:10:38 PM: Build ready to start
11:10:40 PM: build-image version: 122b31996ccaffd45d820a452d6227f8312110cc (focal)
11:10:40 PM: build-image tag: v4.5.3
11:10:40 PM: buildbot version: b0c97e610018064036a967f277f8af9d873774d1
11:10:41 PM: Fetching cached dependencies
11:10:41 PM: Failed to fetch cache, continuing with build
11:10:41 PM: Starting to prepare the repo for build
11:10:41 PM: No cached dependencies found. Cloning fresh repo
11:10:41 PM: git clone https://github.com/Angryman18/React-webpck-babel-workbox
11:10:41 PM: Preparing Git Reference refs/heads/master
11:10:42 PM: Parsing package.json dependencies
11:10:43 PM: Starting build script
11:10:43 PM: Installing dependencies
11:10:43 PM: Python version set to 2.7
11:10:43 PM: Downloading and installing node v16.14.0...
11:10:43 PM: Downloading https://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz...
11:10:44 PM: Computing checksum with sha256sum
11:10:44 PM: Checksums matched!
11:10:47 PM: Now using node v16.14.0 (npm v8.3.1)
11:10:47 PM: Started restoring cached build plugins
11:10:47 PM: Finished restoring cached build plugins
11:10:47 PM: Attempting ruby version 2.7.2, read from environment
11:10:48 PM: Using ruby version 2.7.2
11:10:48 PM: Using PHP version 8.0
11:10:48 PM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
11:10:48 PM: Started restoring cached yarn cache
11:10:48 PM: Finished restoring cached yarn cache
11:10:49 PM: No yarn workspaces detected
11:10:49 PM: Started restoring cached node modules
11:10:49 PM: Finished restoring cached node modules
11:10:49 PM: Installing NPM modules using Yarn version 1.22.10
11:10:49 PM: yarn install v1.22.10
11:10:49 PM: [1/4] Resolving packages...
11:10:50 PM: [2/4] Fetching packages...
11:10:59 PM: info fsevents@2.3.2: The platform "linux" is incompatible with this module.
11:10:59 PM: info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
11:10:59 PM: [3/4] Linking dependencies...
11:10:59 PM: warning " > autoprefixer@10.4.2" has unmet peer dependency "postcss@^8.1.0".
11:10:59 PM: warning " > tailwindcss@3.0.23" has unmet peer dependency "postcss@^8.0.9".
11:10:59 PM: warning " > postcss-loader@6.2.1" has unmet peer dependency "postcss@^7.0.0 || ^8.0.1".
11:10:59 PM: warning " > postcss-preset-env@7.4.2" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-color-function@1.0.2" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-font-format-keywords@1.0.0" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-hwb-function@1.0.0" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-ic-unit@1.0.0" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-is-pseudo-class@2.0.0" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-normalize-display-values@1.0.0" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-oklab-function@1.0.1" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > @csstools/postcss-progressive-custom-properties@1.2.0" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > css-blank-pseudo@3.0.3" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > css-has-pseudo@3.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > css-prefers-color-scheme@6.0.3" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-attribute-case-insensitive@5.0.0" has unmet peer dependency "postcss@^8.0.2".
11:10:59 PM: warning "postcss-preset-env > postcss-color-functional-notation@4.2.2" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-color-hex-alpha@8.0.3" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-color-rebeccapurple@7.0.2" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > postcss-custom-media@8.0.0" has unmet peer dependency "postcss@^8.1.0".
11:10:59 PM: warning "postcss-preset-env > postcss-custom-properties@12.1.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-custom-selectors@6.0.0" has unmet peer dependency "postcss@^8.1.2".
11:10:59 PM: warning "postcss-preset-env > postcss-dir-pseudo-class@6.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-double-position-gradients@3.1.0" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-env-function@4.0.5" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-focus-visible@6.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-focus-within@5.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-font-variant@5.0.0" has unmet peer dependency "postcss@^8.1.0".
11:10:59 PM: warning "postcss-preset-env > postcss-gap-properties@3.0.3" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-image-set-function@4.0.6" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-initial@4.0.1" has unmet peer dependency "postcss@^8.0.0".
11:10:59 PM: warning "postcss-preset-env > postcss-lab-function@4.1.1" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-logical@5.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-media-minmax@5.0.0" has unmet peer dependency "postcss@^8.1.0".
11:10:59 PM: warning "postcss-preset-env > postcss-nesting@10.1.2" has unmet peer dependency "postcss@^8.3".
11:10:59 PM: warning "postcss-preset-env > postcss-overflow-shorthand@3.0.3" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-page-break@3.0.4" has unmet peer dependency "postcss@^8".
11:10:59 PM: warning "postcss-preset-env > postcss-place@7.0.4" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-pseudo-class-any-link@7.1.1" has unmet peer dependency "postcss@^8.4".
11:10:59 PM: warning "postcss-preset-env > postcss-replace-overflow-wrap@4.0.0" has unmet peer dependency "postcss@^8.0.3".
11:10:59 PM: warning "postcss-preset-env > postcss-selector-not@5.0.0" has unmet peer dependency "postcss@^8.1.0".
11:11:01 PM: [4/4] Building fresh packages...
11:11:01 PM: Done in 11.95s.
11:11:01 PM: NPM modules installed using Yarn
11:11:01 PM: Started restoring cached go cache
11:11:01 PM: Finished restoring cached go cache
11:11:02 PM: go version go1.16.5 linux/amd64
11:11:02 PM: go version go1.16.5 linux/amd64
11:11:02 PM: Installing missing commands
11:11:02 PM: Verify run directory
11:11:03 PM: ​
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM:   Netlify Build                                                 
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM: ​
11:11:03 PM: ❯ Version
11:11:03 PM:   @netlify/build 26.4.0
11:11:03 PM: ​
11:11:03 PM: ❯ Flags
11:11:03 PM:   baseRelDir: true
11:11:03 PM:   buildId: 62264396ded51900094b3a6e
11:11:03 PM:   deployId: 62264396ded51900094b3a70
11:11:03 PM: ​
11:11:03 PM: ❯ Current directory
11:11:03 PM:   /opt/build/repo
11:11:03 PM: ​
11:11:03 PM: ❯ Config file
11:11:03 PM:   No config file was defined: using default values.
11:11:03 PM: ​
11:11:03 PM: ❯ Context
11:11:03 PM:   production
11:11:03 PM: ​
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM:   1. Build command from Netlify app                             
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM: ​
11:11:03 PM: $ yarn build
11:11:03 PM: yarn run v1.22.10
11:11:03 PM: $ webpack --mode production --config webpack.prod.js
11:11:03 PM: CLI for webpack must be installed.
11:11:03 PM:   webpack-cli (https://github.com/webpack/webpack-cli)
11:11:03 PM: We will use "yarn" to install the CLI via "yarn add -D webpack-cli".
11:11:03 PM: Do you want to install 'webpack-cli' (yes/no): error Command failed with exit code 1.
11:11:03 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
11:11:03 PM: ​
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM:   "build.command" failed                                        
11:11:03 PM: ────────────────────────────────────────────────────────────────
11:11:03 PM: ​
11:11:03 PM:   Error message
11:11:03 PM:   Command failed with exit code 1: yarn build
11:11:03 PM: ​
11:11:03 PM:   Error location
11:11:03 PM:   In Build command from Netlify app:
11:11:03 PM:   yarn build
11:11:03 PM: ​
11:11:03 PM:   Resolved config
11:11:03 PM:   build:
11:11:03 PM:     command: yarn build
11:11:03 PM:     commandOrigin: ui
11:11:03 PM:     environment:
11:11:03 PM:       - CI
11:11:03 PM:       - NODE_ENV
11:11:03 PM:     publish: /opt/build/repo/dist
11:11:03 PM:     publishOrigin: ui
11:11:04 PM: Caching artifacts
11:11:04 PM: Started saving node modules
11:11:04 PM: Finished saving node modules
11:11:04 PM: Started saving build plugins
11:11:04 PM: Finished saving build plugins
11:11:04 PM: Started saving yarn cache
11:11:08 PM: Finished saving yarn cache
11:11:08 PM: Started saving pip cache
11:11:08 PM: Finished saving pip cache
11:11:08 PM: Started saving emacs cask dependencies
11:11:08 PM: Finished saving emacs cask dependencies
11:11:08 PM: Started saving maven dependencies
11:11:08 PM: Finished saving maven dependencies
11:11:08 PM: Started saving boot dependencies
11:11:08 PM: Finished saving boot dependencies
11:11:08 PM: Started saving rust rustup cache
11:11:08 PM: Finished saving rust rustup cache
11:11:08 PM: Started saving go dependencies
11:11:08 PM: Finished saving go dependencies
11:11:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:11:12 PM: Creating deploy upload records
11:11:13 PM: Failing build: Failed to build site
11:11:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:11:13 PM: Finished processing build request in 33.282694546s

this is the entire deploy log and my package.json is below

{
  "name": "bugtracker",
  "version": "1.0.0",
  "description": "Bug Tracker Applicaiton",
  "main": "index.js",
  "author": "Shyam Mahanta",
  "Homepage": "/",
  "license": "MIT",
  "private": true,
  "scripts": {
    "start": "webpack serve --config webpack.dev.js",
    "build": "webpack --mode production --config webpack.prod.js",
    "prod": "yarn run build && serve -s dist"
  },
  "devDependencies": {
    "@babel/core": "^7.17.5",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "babel-loader": "^8.2.3",
    "copy-webpack-plugin": "^10.2.4",
    "css-loader": "^6.6.0",
    "css-minimizer-webpack-plugin": "^3.4.1",
    "dotenv-webpack": "^7.1.0",
    "file-loader": "^6.2.0",
    "html-webpack-plugin": "^5.5.0",
    "mini-css-extract-plugin": "^2.5.3",
    "postcss-loader": "^6.2.1",
    "postcss-preset-env": "^7.4.2",
    "serve": "^13.0.2",
    "terser-webpack-plugin": "^5.3.1",
    "webpack": "^5.70.0",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.7.4",
    "workbox-core": "^6.5.1",
    "workbox-expiration": "^6.5.1",
    "workbox-precaching": "^6.5.1",
    "workbox-routing": "^6.5.1",
    "workbox-strategies": "^6.5.1",
    "workbox-webpack-plugin": "^6.5.1",
    "workbox-window": "^6.5.1"
  },
  "dependencies": {
    "autoprefixer": "^10.4.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "sass-loader": "^12.6.0",
    "tailwindcss": "^3.0.23"
  }
}

hi there,

the problem is in the line above, sadly. You are asking our robots to run the command β€œyarn build” but there is no such command defined in your package.json, so we don;t know what to do, and the build fails with an error.

does this work locally?