Build Command Failed: error code 127: webpack --config webpack.config.js

Hello!

I have been trying to deploy my Netifly site for some time now and can’t seem to get past “Build Command Failed. Error Code 127”.

Here is some further context:

Netifly site name: https://capable-douhua-25721f.netlify.app](https://capable-douhua-25721f.netlify.app/

Build log:

3:02:10 PM: Netlify Build
3:02:10 PM: ────────────────────────────────────────────────────────────────
3:02:10 PM: ​
3:02:10 PM: ❯ Version
3:02:10 PM: @netlify/build 29.33.6
3:02:10 PM: ​
3:02:10 PM: ❯ Flags
3:02:10 PM: baseRelDir: true
3:02:10 PM: buildId: 65ca32e4981da200076e434a
3:02:10 PM: deployId: 65ca32e4981da200076e434c
3:02:10 PM: ​
3:02:10 PM: ❯ Current directory
3:02:10 PM: /opt/build/repo
3:02:10 PM: ​
3:02:10 PM: ❯ Config file
3:02:10 PM: No config file was defined: using default values.
3:02:10 PM: ​
3:02:10 PM: ❯ Context
3:02:10 PM: production
3:02:10 PM: ​
3:02:10 PM: Build command from Netlify app
3:02:10 PM: ────────────────────────────────────────────────────────────────
3:02:10 PM: ​
3:02:10 PM: $ webpack --config webpack.config.js
3:02:10 PM: bash: webpack: command not found
3:02:10 PM: ​
3:02:10 PM: “build.command” failed
3:02:10 PM: ────────────────────────────────────────────────────────────────
3:02:10 PM: ​
3:02:10 PM: Error message
3:02:10 PM: Command failed with exit code 127: webpack --config webpack.config.js (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
3:02:10 PM: ​
3:02:10 PM: Error location
3:02:10 PM: In Build command from Netlify app:
3:02:10 PM: webpack --config webpack.config.js
3:02:10 PM: ​
3:02:10 PM: Resolved config
3:02:10 PM: build:
3:02:10 PM: base: /opt/build/repo
3:02:10 PM: command: webpack --config webpack.config.js
3:02:10 PM: commandOrigin: ui
3:02:10 PM: environment:
3:02:10 PM: - NODE_VERSION
3:02:10 PM: - NPM_VERSION
3:02:10 PM: publish: /opt/build/repo/public
3:02:10 PM: publishOrigin: ui
3:02:11 PM: Failed during stage “building site”: Build script returned non-zero exit code: 2
3:02:11 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:02:11 PM: Failing build: Failed to build site
3:02:11 PM: Finished processing build request in 14.007s

I’m struggling with what to do next to try and fix it. I had a look through the forums and saw lots of people mention issues around the 127 error code but nothing directly related to Webpack.

When I run my build command locally “webpack --config webpack.config.js”, everything seems to work as expected:

webpack --config webpack.config.js
[BABEL] Note: The code generator has deoptimised the styling of /Users/alfiebatten/Desktop/garbs/garbs/src/components/landingSection/landingLogo.js as it exceeds the max of 500KB.
assets by status 138 MiB [cached] 23 assets
assets by path . 2.22 MiB
asset bundle.js 2.22 MiB [compared for emit] (name: main) 1 related asset
asset index.html 876 bytes [emitted]
runtime modules 2.6 KiB 9 modules
modules by path ./src/ 1.04 MiB (javascript) 26.3 KiB (asset)
modules by path ./src/components/ 1.04 MiB 45 modules
modules by path ./src/.scss 2.95 KiB
./src/index.scss 1.19 KiB [built] [code generated]
./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/index.scss 1.76 KiB [built] [code generated]
./src/index.js 989 bytes [built] [code generated]
./src/BiggerDisplay.otf 42 bytes (javascript) 26.3 KiB (asset) [built] [code generated]
modules by path ./node_modules/ 1.09 MiB
modules by path ./node_modules/style-loader/dist/runtime/
.js 5.84 KiB 6 modules
modules by path ./node_modules/react-dom/ 1000 KiB 3 modules
modules by path ./node_modules/css-loader/dist/runtime/*.js 3.33 KiB 3 modules
modules by path ./node_modules/react/ 85.7 KiB 2 modules
modules by path ./node_modules/scheduler/ 17.3 KiB 2 modules
webpack 5.90.1 compiled successfully in 1512 ms

If anyone knows of anything that may fix it I would love to hear it!

Thanks so much,
Alfie

Hi @alfie,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Looks like the error starts here:

1:30:43 PM: $ webpack --config webpack.config.js

1:30:43 PM: bash: webpack: command not found

Are you able to successful build locally?

We have this support guide that can help troubleshoot builds:

Hi @Melvin,

Thanks so much for getting back to me!

So if I run webpack --config webpack.config.js locally I actually get the same error zsh: command not found: webpack, which is weird because I have webpack installed.

If I run npx webpack --config webpack.config.js locally though it seems to work and I get the following:

npx webpack --config webpack.config.js
[BABEL] Note: The code generator has deoptimised the styling of /Users/alfiebatten/Desktop/garbs/garbs/src/components/landingSection/landingLogo.js as it exceeds the max of 500KB.
assets by status 138 MiB [cached] 23 assets
assets by path . 2.23 MiB
  asset bundle.js 2.23 MiB [compared for emit] (name: main) 1 related asset
  asset index.html 1.43 KiB [emitted]
runtime modules 2.6 KiB 9 modules
modules by path ./src/ 1.05 MiB (javascript) 26.3 KiB (asset)
  modules by path ./src/components/ 1.05 MiB 45 modules
  modules by path ./src/*.scss 2.95 KiB
    ./src/index.scss 1.19 KiB [built] [code generated]
    ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/index.scss 1.76 KiB [built] [code generated]
  ./src/index.js 987 bytes [built] [code generated]
  ./src/BiggerDisplay.otf 42 bytes (javascript) 26.3 KiB (asset) [built] [code generated]
modules by path ./node_modules/ 1.09 MiB
  modules by path ./node_modules/style-loader/dist/runtime/*.js 5.84 KiB 6 modules
  modules by path ./node_modules/react-dom/ 1000 KiB 3 modules
  modules by path ./node_modules/css-loader/dist/runtime/*.js 3.33 KiB 3 modules
  modules by path ./node_modules/react/ 85.7 KiB 2 modules
  modules by path ./node_modules/scheduler/ 17.3 KiB 2 modules
webpack 5.90.1 compiled successfully in 6774 ms

However, if I change the build command in Netifly to npx webpack --config webpack.config.js and trigger a new deploy I get the following error:

1:11:58 PM: Netlify Build                                                 
1:11:58 PM: ────────────────────────────────────────────────────────────────
1:11:58 PM: ​
1:11:58 PM: ❯ Version
1:11:58 PM:   @netlify/build 29.34.1
1:11:58 PM: ​
1:11:58 PM: ❯ Flags
1:11:58 PM:   baseRelDir: true
1:11:58 PM:   buildId: 65ce0d7fe97acf06db07071b
1:11:58 PM:   deployId: 65ce0d7fe97acf06db07071d
1:11:58 PM: ​
1:11:58 PM: ❯ Current directory
1:11:58 PM:   /opt/build/repo
1:11:58 PM: ​
1:11:58 PM: ❯ Config file
1:11:58 PM:   No config file was defined: using default values.
1:11:58 PM: ​
1:11:58 PM: ❯ Context
1:11:58 PM:   production
1:11:58 PM: ​
1:11:58 PM: Build command from Netlify app                                
1:11:58 PM: ────────────────────────────────────────────────────────────────
1:11:58 PM: ​
1:11:58 PM: $ npx webpack --config webpack.config.js
1:11:58 PM: npm WARN exec The following package was not found and will be installed: webpack@5.90.1
1:12:01 PM: CLI for webpack must be installed.
1:12:01 PM:   webpack-cli (https://github.com/webpack/webpack-cli)
1:12:01 PM: We will use "npm" to install the CLI via "npm install -D webpack-cli".
1:12:01 PM: Do you want to install "webpack-cli" (yes/no): ​
1:12:01 PM: "build.command" failed                                        
1:12:01 PM: ────────────────────────────────────────────────────────────────
1:12:01 PM: ​
1:12:01 PM:   Error message
1:12:01 PM:   Command failed with exit code 1: npx webpack --config webpack.config.js (https://ntl.fyi/exit-code-1)
1:12:01 PM: ​
1:12:01 PM:   Error location
1:12:01 PM:   In Build command from Netlify app:
1:12:01 PM:   npx webpack --config webpack.config.js
1:12:01 PM: ​
1:12:01 PM:   Resolved config
1:12:01 PM:   build:
1:12:01 PM:     base: /opt/build/repo
1:12:01 PM:     command: npx webpack --config webpack.config.js
1:12:01 PM:     commandOrigin: ui
1:12:01 PM:     publish: /opt/build/repo/dist
1:12:01 PM:     publishOrigin: ui
1:12:01 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:12:01 PM: Failing build: Failed to build site
1:12:01 PM: Finished processing build request in 17.553s
1:12:01 PM: Failed during stage "building site": Build script returned non-zero exit code: 2

I have webpack-cli installed but for some reason its not picking it up. I’ve tried countless things and really can’t seem to be getting anywhere.

Thanks for sending over the debugging guide, I’ve read through it and also added the 4 environment variables for NODE_ENV, NODE_VERSION, NPM_VERSION and YARN_VERSION.

I set them to the following:

NODE_ENV: development
NODE_VERSION: 18.2.0
NPM_VERSION: 9.8.1
YARN_VERSION: 1.22.19

I set these as per the version my site runs locally on, through running -v in terminal, as per the below:

➜  garbs git:(main) ✗ node -v
v18.2.0
➜  garbs git:(main) ✗ npm -v
9.8.1
➜  garbs git:(main) ✗ yarn -v
1.22.19

I ran a new build and still getting the same errors as above. Any help or ideas on how to fix would be greatly appreciated!

Thanks so much,
Alfie

Hi @alfie,

Thanks for following up. I do see that you’re latest build was successful, you were able to resolve the issue?