Command failed with exit code 127: npm run build (https://ntl.fyi/exit-code-127) - Project with JS and Webpack bild bundler

I’ve been trying to deploy my project with HTML, CSS and Javascript on Netlify for quite some time and the platform always replies me with this error message.
I’ve read many similar messages complaining about the same issue, but it seems that mine is a little different.
Could someone kindly explain me what should I do in order to solve the problem?

5:05:36 PM: Netlify Build
5:05:36 PM: ────────────────────────────────────────────────────────────────
5:05:36 PM: ​
5:05:36 PM: ❯ Version
5:05:36 PM: @netlify/build 29.33.6
5:05:36 PM: ​
5:05:36 PM: ❯ Flags
5:05:36 PM: baseRelDir: true
5:05:36 PM: buildId: 65c64d45972428103617c266
5:05:36 PM: deployId: 65c64d45972428103617c268
5:05:36 PM: ​
5:05:36 PM: ❯ Current directory
5:05:36 PM: /opt/build/repo/src
5:05:36 PM: ​
5:05:36 PM: ❯ Config file
5:05:36 PM: No config file was defined: using default values.
5:05:36 PM: ​
5:05:36 PM: ❯ Context
5:05:36 PM: production
5:05:36 PM: ​
5:05:36 PM: Build command from Netlify app
5:05:36 PM: ────────────────────────────────────────────────────────────────
5:05:36 PM: ​
5:05:36 PM: $ npm run build
5:05:37 PM: Failed during stage “building site”: Build script returned non-zero exit code: 2
5:05:37 PM: > progetto-finale-js-advanced@1.0.0 build
5:05:37 PM: > webpack --mode production
5:05:37 PM: sh: 1: webpack: not found
5:05:37 PM: ​
5:05:37 PM: “build.command” failed
5:05:37 PM: ────────────────────────────────────────────────────────────────
5:05:37 PM: ​
5:05:37 PM: Error message
5:05:37 PM: Command failed with exit code 127: npm run build (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
5:05:37 PM: ​
5:05:37 PM: Error location
5:05:37 PM: In Build command from Netlify app:
5:05:37 PM: npm run build
5:05:37 PM: ​
5:05:37 PM: Resolved config
5:05:37 PM: build:
5:05:37 PM: base: /opt/build/repo/src
5:05:37 PM: command: npm run build
5:05:37 PM: commandOrigin: ui
5:05:37 PM: publish: /opt/build/repo/src/docs
5:05:37 PM: publishOrigin: ui
5:05:37 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:05:37 PM: Failing build: Failed to build site
5:05:37 PM: Finished processing build request in 11.06s

@EliaGiolli The relevant part is:

5:05:37 PM: sh: 1: webpack: not found

Ensure your package.json / package-lock.json contains webpack as a dependency, so that it gets installed when your Netlify build runs.

“dependencies”: {
“axios”: “^1.6.7”,
“html-loader”: “^5.0.0”,
“html-webpack-plugin”: “^5.6.0”,
“lodash.get”: “^4.4.2”
},
“devDependencies”: {
@babel/core”: “^7.23.7”,
@babel/preset-env”: “^7.23.8”,
“babel-loader”: “^9.1.3”,
“css-loader”: “^6.9.1”,
“style-loader”: “^3.3.4”,
“webpack”: “^5.90.0”,
“webpack-cli”: “^5.1.4”,
“webpack-dev-server”: “^4.15.1”

As you can see, I already installed webpack as a dependecy. Is there anything else I should try to solve the problem? :smiling_face:

Move all devDependencies to dependencies.

1 Like

“dependencies”: {
@babel/core”: “^7.23.7”,
@babel/preset-env”: “^7.23.8”,
“babel-loader”: “^9.1.3”,
“css-loader”: “^6.9.1”,
“style-loader”: “^3.3.4”,
“webpack”: “^5.90.0”,
“webpack-cli”: “^5.1.4”,
“webpack-dev-server”: “^4.15.1”,
“axios”: “^1.6.7”,
“html-loader”: “^5.0.0”,
“html-webpack-plugin”: “^5.6.0”,
“lodash.get”: “^4.4.2”
}

I moved every dev dependency into dependency but netflify keeps showing me the same error message

I’m not seeing that change: Project-BookSearch/package.json at main · EliaGiolli/Project-BookSearch (github.com)