Command failed with exit code 127: npm run build

Hi,
When I want to deploy my website, I have this message:

1:37:38 AM: ────────────────────────────────────────────────────────────────
1:37:38 AM:   "build.command" failed                                        
1:37:38 AM: ────────────────────────────────────────────────────────────────
1:37:38 AM: ​
1:37:38 AM:   Error message
1:37:38 AM:   Command failed with exit code 127: npm run build (https://ntl.fyi/exit-code-127)
1:37:38 AM: ​
1:37:38 AM:   Error location
1:37:38 AM:   In Build command from Netlify app:
1:37:38 AM:   npm run build
1:37:38 AM: ​
1:37:38 AM:   Resolved config
1:37:38 AM:   build:
1:37:38 AM:     base: /opt/build/repo/pages
1:37:38 AM:     command: npm run build
1:37:38 AM:     commandOrigin: ui
1:37:38 AM:     environment:
1:37:38 AM:       - NEXT_PRIVATE_TARGET
1:37:38 AM:     publish: /opt/build/repo/pages/.nextjs
1:37:38 AM:     publishOrigin: ui
1:37:38 AM:   plugins:
1:37:38 AM:     - inputs: {}
1:37:38 AM:       origin: ui
1:37:39 AM: Creating deploy upload records
1:37:38 AM:       package: '@netlify/plugin-nextjs'
1:37:38 AM: Caching artifacts
1:37:38 AM: Started saving build plugins
1:37:38 AM: Finished saving build plugins
1:37:39 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:37:38 AM: Started saving pip cache
1:37:38 AM: Finished saving pip cache
1:37:38 AM: Started saving emacs cask dependencies
1:37:38 AM: Finished saving emacs cask dependencies
1:37:38 AM: Started saving maven dependencies
1:37:38 AM: Finished saving maven dependencies
1:37:38 AM: Started saving boot dependencies
1:37:38 AM: Finished saving boot dependencies
1:37:38 AM: Started saving rust rustup cache
1:37:38 AM: Finished saving rust rustup cache
1:37:38 AM: Started saving go dependencies
1:37:38 AM: Finished saving go dependencies
1:37:39 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:37:39 AM: Failing build: Failed to build site
1:37:40 AM: Finished processing build request in 25.497490227s

I searched on the forum, but no topic corresponds exactly to my error message.

Hi @MiKalem898, based on your error message it seems you are trying to deploy a Nextjs site.
If possible can you share a repository of the site for me to help with the debugging?
Thanks.

The github repo : https://github.com/MiKalem898/NicePencil

Hi @MiKalem898, thanks for sharing the repository.
It seems you have errors in your code which is causing the deployment to fail.

  1. Build command from Netlify app

Kindly take a look at your deploy log and start reading from the quote above. The deploy log shows were the errors are in your code.

Kindly fix the syntax errors and then redeploy again to see if it works.
Let me know the outcome.

Thanks.

I have this but I don’t know how to fix this ?

1:37:38 AM: sh: 1: next: not found

Hi @MiKalem898, kindly change your build settings to the below
Build command: next build && next export
Publish directory: out

If you are getting the error in development on local computer, delete the package-lock.json file and then run the code below.
if you are using npm - npm install
if you are using yarn - yarn

Thanks.

It’s published ! I made a new site on Netlify because this wasn’t working and now its good ! But, I must replace the codes like routes.home by "/" or routes.passwordGenerator by "/password- ingenerator" ect, in my code because I have this error:

1:20:57 PM: ./Components/Links/Links.js
1:20:57 PM: Module not found: Can't resolve '../../Config/routes' in '/opt/build/repo/Components/Links'
1:20:57 PM: Import trace for requested module:
1:20:57 PM: ./pages/index.js
1:20:57 PM: ./Components/UI/Layout/Layout.js
1:20:57 PM: Module not found: Can't resolve '../../../Config/routes' in '/opt/build/repo/Components/UI/Layout'
1:20:57 PM: Import trace for requested module:
1:20:57 PM: ./pages/_app.js
1:20:57 PM: ./pages/_app.js
1:20:57 PM: Module not found: Can't resolve '../Config/routes' in '/opt/build/repo/pages'
1:20:57 PM: ./pages/index.js
1:20:57 PM: Module not found: Can't resolve '../Config/routes' in '/opt/build/repo/pages'
1:20:57 PM: > Build failed because of webpack errors

Not a big problem but a bit boring

The website is https://nice-pencil.netlify.app (it’s in french)

@MiKalem898 kindly also share a repository if possible for me to check it out.
Thanks.

Hi @MiKalem898 glad to know you have been able to publish your site.