Command failed with exit code 127

Hello,

I am having trouble deploying my site.

I have read through some similar posts regarding the error message “Command failed with exit code 127”. I have read through some docs and added Node and NPM variables into my Netlify environment settings but i am still getting the same error.

Please could someone help?

9:47:23 AM: Netlify Build
9:47:23 AM: ────────────────────────────────────────────────────────────────
9:47:23 AM: ​
9:47:23 AM: ❯ Version
9:47:23 AM: @netlify/build 29.41.3
9:47:23 AM: ​
9:47:23 AM: ❯ Flags
9:47:23 AM: baseRelDir: true
9:47:23 AM: buildId: 6645c7f4715a687839cdd058
9:47:23 AM: deployId: 6645c7f4715a687839cdd05a
9:47:23 AM: ​
9:47:23 AM: ❯ Current directory
9:47:23 AM: /opt/build/repo
9:47:23 AM: ​
9:47:23 AM: ❯ Config file
9:47:23 AM: No config file was defined: using default values.
9:47:23 AM: ​
9:47:23 AM: ❯ Context
9:47:23 AM: production
9:47:23 AM: ​
9:47:23 AM: Build command from Netlify app
9:47:23 AM: ────────────────────────────────────────────────────────────────
9:47:23 AM: ​
9:47:23 AM: $ next build
9:47:23 AM: bash: next: command not found
9:47:23 AM: ​
9:47:23 AM: “build.command” failed
9:47:23 AM: ────────────────────────────────────────────────────────────────
9:47:23 AM: ​
9:47:23 AM: Error message
9:47:23 AM: Command failed with exit code 127: next build (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
9:47:23 AM: ​
9:47:23 AM: Error location
9:47:23 AM: In Build command from Netlify app:
9:47:23 AM: next build
9:47:23 AM: ​
9:47:23 AM: Resolved config
9:47:23 AM: build:
9:47:23 AM: command: next build
9:47:23 AM: commandOrigin: ui
9:47:23 AM: environment:
9:47:23 AM: - NODE_VERSION
9:47:23 AM: - NPM_VERSION
9:47:23 AM: publish: /opt/build/repo/.next
9:47:23 AM: publishOrigin: ui
9:47:23 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:47:24 AM: Failing build: Failed to build site
9:47:24 AM: Finished processing build request in 16.504s
9:47:24 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)

@melech Command failed with exit code 127 isn’t the root cause of the error, it’s the result.

Your actual error is:

next does not exist

Make sure it is a dependency in your package.json

but it does. Doesn’t it?

{
“name”: “moonrise”,
“version”: “0.1.0”,
“private”: true,
“scripts”: {
“dev”: “next dev”,
“build”: “next build”,
“start”: “next start”,
“lint”: “next lint”,
“check-node-version”: “node -v”
},
“dependencies”: {
“chakra-ui/react”: “^2.8.2”,
“emotion/react”: “^11.11.4”,
“emotion/styled”: “^11.11.5”,
“glidejs/glide”: “^3.6.0”,
“hookform/resolvers”: “^3.3.4”,
“iconify/react”: “^4.1.1”,
“clsx”: “^2.0.0”,
“framer-motion”: “^10.18.0”,
“next”: “^14.2.3”,
“nodemailer”: “^6.9.13”,
“react”: “^18”,
“react-dom”: “^18”,
“react-hook-form”: “^7.51.0”,
“react-slick”: “^0.29.0”,
“slick-carousel”: “^1.8.1”,
“tailwind-merge”: “^2.0.0”,
“zod”: “^3.22.4”
},
“devDependencies”: {
“types/node”: “20.10.0”,
“types/react”: “18.2.39”,
“types/react-slick”: “^0.23.13”,
“autoprefixer”: “^10.0.1”,
“daisyui”: “^4.7.2”,
“eslint”: “^8”,
“eslint-config-next”: “14.0.3”,
“postcss”: “^8”,
“tailwindcss”: “^3.4.1”
},
“engines”: {
“node”: “20.10.0”,
“npm”: “10.2.5”
}
}

I can’t see your files so cannot say, but as far as the build is concerned it doesn’t.

Just double check your build settings and the file etc.

Ensure the package.json is in the Base directory as per:
https://docs.netlify.com/configure-builds/overview/#definitions

If everything is correct and still doesn’t work then you may be dealing with Next.js specific junk, since Netlify has additional handling for it, see those docs here:
https://docs.netlify.com/frameworks/next-js/overview/

Please could I have a bit more help here. I’m not sure what I should be looking for on these docs. I copied and pasted my package.json code above. You can’t see that?

My package.json file is in my base directory

Here is my latest deploy log. I changed the engines to match what I saw on the Netlify docs I also made a netlify.toml filewith command = “npm run build” and publish =“.net”

10:37:44 AM: Netlify Build                                                 
10:37:44 AM: ────────────────────────────────────────────────────────────────
10:37:44 AM: ​
10:37:44 AM: ❯ Version
10:37:44 AM:   @netlify/build 29.41.3
10:37:44 AM: ​
10:37:44 AM: ❯ Flags
10:37:44 AM:   baseRelDir: true
10:37:44 AM:   buildId: 6645d3d176c4560007f372a1
10:37:44 AM:   deployId: 6645d3d176c4560007f372a3
10:37:44 AM: ​
10:37:44 AM: ❯ Current directory
10:37:44 AM:   /opt/build/repo
10:37:44 AM: ​
10:37:44 AM: ❯ Config file
10:37:44 AM:   No config file was defined: using default values.
10:37:44 AM: ​
10:37:44 AM: ❯ Context
10:37:44 AM:   production
10:37:44 AM: ​
10:37:44 AM: Build command from Netlify app                                
10:37:44 AM: ────────────────────────────────────────────────────────────────
10:37:44 AM: ​
10:37:44 AM: $ next build
10:37:44 AM: bash: next: command not found
10:37:44 AM: ​
10:37:44 AM: "build.command" failed                                        
10:37:44 AM: ────────────────────────────────────────────────────────────────
10:37:44 AM: ​
10:37:44 AM:   Error message
10:37:44 AM:   Command failed with exit code 127: next build (https://ntl.fyi/exit-code-127)
10:37:44 AM: ​
10:37:44 AM:   Error location
10:37:44 AM:   In Build command from Netlify app:
10:37:44 AM:   next build
10:37:44 AM: ​
10:37:44 AM:   Resolved config
10:37:44 AM:   build:
10:37:44 AM:     command: next build
10:37:44 AM:     commandOrigin: ui
10:37:44 AM:     publish: /opt/build/repo/.next
10:37:44 AM:     publishOrigin: ui
10:37:44 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:37:45 AM: Failing build: Failed to build site
10:37:45 AM: Finished processing build request in 12.152s
10:37:45 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)

@melech I can see the code you pasted in this thread but that’s all I can see, I don’t work for Netlify and don’t have any special visibility, I can only see what you show.

The package.json contents tell me that the same thing it tells you, which is that “next”: “^14.2.3”, is specified under dependencies.

I don’t work with Next.js myself and I don’t tend to assist people working with it, since the additional “automatic” functionality hosts have and the middleware or things like SSR add points of failure I don’t have an interest in.

You can try changing your build command to npm run build.

If your repository is public please link to it.

ah, my apologies. I thought you worked for Netlify! Thank you for your help.

Here is a link to my repo: GitHub - edmelech/moonrise

also, i tried the changing the build command in the scripts to npm run build and it didn’t work. it’s currently still on that.

Straight away I can see the package.json is not in the root of the repository:

Since it’s in moonrise you would want to set your Base directory to that.

I see. How do i set my base directory to moonrise? I have made a netlify.toml file with the below but it is still not working.

[build]
  base="moonrise"
  command = "npm run build"
  publish = "moonrise/build"

@melech Normally I would set the Base directory in the Netlify UI, as per the documentation I originally linked:
https://docs.netlify.com/configure-builds/overview/#build-settings

The documentation for using File-based Configuration is here:
https://docs.netlify.com/configure-builds/file-based-configuration/

If you want to set Base directory with the netlify.toml you would need to ensure that file is in the root of the repository, as they mention here:
https://docs.netlify.com/configure-builds/file-based-configuration/#file-location

You currently have your netlify.toml in the moonrise folder too:

The main thing to understand is that most of the time, under normal “non-framework specific” conditions, Netlify doesn’t look through your repository to try and locate things or auto-determine what to run.

You set where it should navigate to, what it should execute etc.

1 Like

i figured out what the issue was. I must have accidentally set up my git remote one level higher in my folder structure. Thanks for your help. onto the OTHER errors now :sweat_smile:

1 Like