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

**URL:** <https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331>\
**Category:** Support\
**Tags:** webpack, building, deployment\
**Created:** [February 12, 2024, 3:08pm UTC](https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331 "2024-02-12T15:08:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfie](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@alfie](https://answers.netlify.com/u/alfie)\
**Post date:** [February 12, 2024, 3:08pm UTC](https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331/1 "2024-02-12T15:08:36Z")

</div>

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)]([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](https://ntl.fyi/exit-code-127))  
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

---

<div class="post-metadata">

**Author:** ![Melvin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/melvin/32/23606_2.png) [@Melvin](https://answers.netlify.com/u/Melvin)\
**Post date:** [February 14, 2024, 6:47pm UTC](https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331/2 "2024-02-14T18:47:52Z")

</div>

Hi @alfie,

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

Looks like the error starts here:

[https://app.netlify.com/sites/capable-douhua-25721f/deploys/65ca71ca39471100746d745f#L54-L55](https://app.netlify.com/sites/capable-douhua-25721f/deploys/65ca71ca39471100746d745f#L54-L55)

```auto
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:

> [@\[Support Guide\] Debugging Netlify site builds](https://answers.netlify.com/t/support-guide-debugging-netlify-site-builds/142):
>
> Last reviewed by Netlify Support - July 2025 Note: This article is only about builds within Netlify’s Continuous Integration (CI) environment, as [triggered from git commits](https://docs.netlify.com/site-deploys/create-deploys/#deploy-with-git) or from [incoming build webhooks](https://docs.netlify.com/configure-builds/build-hooks/). You can learn more in depth about how Netlify builds your site in this [article about how our build bots build sites](https://www.netlify.com/blog/2016/10/18/how-our-build-bots-build-sites/). Some background There are a fair number of reasons that a build could fail in Netlify’s CI environment, even if building works locally. Testing locally is always the place to …

---

<div class="post-metadata">

**Author:** ![alfie](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@alfie](https://answers.netlify.com/u/alfie)\
**Post date:** [February 15, 2024, 1:25pm UTC](https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331/3 "2024-02-15T13:25:27Z")

</div>

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:

```auto
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:

```auto
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:

```auto
➜ 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

---

<div class="post-metadata">

**Author:** ![Melvin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/melvin/32/23606_2.png) [@Melvin](https://answers.netlify.com/u/Melvin)\
**Post date:** [February 15, 2024, 6:09pm UTC](https://answers.netlify.com/t/build-command-failed-error-code-127-webpack-config-webpack-config-js/112331/4 "2024-02-15T18:09:15Z")

</div>

Hi @alfie,

Thanks for following up. I do see that you’re [latest build](https://app.netlify.com/sites/capable-douhua-25721f/deploys/65ce30a43af72e0008e03926) was successful, you were able to resolve the issue?
