Deployment failure: babel command not found

Deployment fails and it says babel command not found. Though I have it as dev-dependency.

5:05:56 PM: Build ready to start

5:05:58 PM: build-image version: 2dbd444fcdce00cf06325060a8238d5ae3e86774

5:05:58 PM: build-image tag: v3.3.7

5:05:58 PM: buildbot version: 11918e084194721d200458438c92ff8180b3b56c

5:05:58 PM: Fetching cached dependencies

5:05:58 PM: Starting to download cache of 137.7MB

5:05:59 PM: Finished downloading cache in 946.265281ms

5:05:59 PM: Starting to extract cache

5:06:04 PM: Finished extracting cache in 5.18140448s

5:06:04 PM: Finished fetching cache in 6.231792872s

5:06:04 PM: Starting to prepare the repo for build

5:06:05 PM: Preparing Git Reference refs/heads/dev

5:06:05 PM: Starting build script

5:06:05 PM: Installing dependencies

5:06:06 PM: Started restoring cached node version

5:06:09 PM: Finished restoring cached node version

5:06:09 PM: Attempting node version 'v12.14.0' from .nvmrc

5:06:10 PM: v12.14.0 is already installed.

5:06:11 PM: Now using node v12.14.0 (npm v6.13.4)

5:06:11 PM: Attempting ruby version 2.6.2, read from environment

5:06:13 PM: Using ruby version 2.6.2

5:06:13 PM: Using PHP version 5.6

5:06:13 PM: Started restoring cached node modules

5:06:13 PM: Finished restoring cached node modules

5:06:14 PM: Started restoring cached go cache

5:06:14 PM: Finished restoring cached go cache

5:06:14 PM: unset GOOS;

5:06:14 PM: unset GOARCH;

5:06:14 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';

5:06:14 PM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";

5:06:14 PM: go version >&2;

5:06:14 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';

5:06:14 PM: go version go1.12 linux/amd64

5:06:14 PM: Installing missing commands

5:06:14 PM: Verify run directory

5:06:14 PM: Executing user command: npm run build && cd docs && npm install && npm run build

5:06:15 PM: > cb-design-system@1.0.0 build /opt/build/repo

5:06:15 PM: > NODE_ENV=production BABEL_ENV=cjs babel ./src --out-dir ./dist/cjs

5:06:15 PM: sh: 1: babel: not found

5:06:15 PM: npm

5:06:15 PM: ERR! code ELIFECYCLE

5:06:15 PM: npm

5:06:15 PM: ERR!

5:06:15 PM: syscall

5:06:15 PM: spawn

5:06:15 PM: npm

5:06:15 PM: ERR!

5:06:15 PM: file

5:06:15 PM: sh

5:06:15 PM: npm

5:06:15 PM: ERR! errno

5:06:15 PM: ENOENT

5:06:15 PM: npm

5:06:15 PM: ERR! cb-design-system@1.0.0 build: `NODE_ENV=production BABEL_ENV=cjs babel ./src --out-dir ./dist/cjs`

5:06:15 PM: npm

5:06:15 PM: ERR! spawn ENOENT

5:06:15 PM: npm

5:06:15 PM: ERR!

5:06:15 PM: failed during stage 'building site': Build script returned non-zero exit code: 1

5:06:15 PM: npm

5:06:15 PM: ERR!

5:06:15 PM: Failed at the cb-design-system@1.0.0 build script.

5:06:15 PM: npm

5:06:15 PM: ERR! This is probably not a problem with npm. There is likely additional logging output above.

5:06:15 PM: npm

5:06:15 PM: ERR! A complete log of this run can be found in:

5:06:15 PM: Shutting down logging, 19 messages pending

5:06:15 PM: npm ERR!

Hello @Kameshwaran and welcome!

Can you share your package.json also please?

By the way, I’m not sure if your build command works on Netlify?
npm run build && cd docs && npm install && npm run build

You build, go to the docs folder (don’t think this works on Netlify), npm install (which Netlify does automatically) and then you build again?

Here it is:

{
  "name": "xxxx",
  "version": "1.0.0",
  "description": "xxxx",
  "author": "xxxx",
  "license": "MIT",
  "repository": "xxx/xx-xx-xx",
  "main": "dist/cjs/index.js",
  "engines": {
    "node": ">=8",
    "npm": ">=5"
  },
  "scripts": {
    "build": "BABEL_ENV=cjs babel ./src --out-dir ./dist/cjs",
    "start": "watch 'npm run build' src"
  },
  "peerDependencies": {
    "@emotion/styled": "^10.0.27",
    "prop-types": "^15.5.4",
    "react": "^15.0.0 || ^16.0.0",
    "react-dom": "^15.0.0 || ^16.0.0",
    "theme-ui": "^0.3.1",
    "react-transition-group": "^4.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.7",
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/plugin-proposal-export-default-from": "^7.8.3",
    "@babel/plugin-proposal-object-rest-spread": "^7.8.3",
    "@babel/plugin-proposal-optional-chaining": "^7.8.3",
    "@babel/plugin-transform-runtime": "^7.8.3",
    "@babel/preset-env": "^7.8.7",
    "@babel/preset-react": "^7.8.3",
    "@emotion/styled": "^10.0.27",
    "eslint": "^5.0.1",
    "eslint-config-standard": "^11.0.0",
    "eslint-config-standard-react": "^6.0.0",
    "eslint-plugin-import": "^2.13.0",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^4.0.0",
    "eslint-plugin-react": "^7.10.0",
    "eslint-plugin-standard": "^3.1.0",
    "prop-types": "^15.5.4",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-scripts": "^1.1.4",
    "react-transition-group": "^4.3.0",
    "theme-ui": "^0.3.1",
    "watch": "^1.0.2"
  },
  "files": [
    "dist"
  ]
}

I always have these in my package.json:

"devDependencies": {
    "@babel/core": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "babel-core": "^7.0.0-bridge.0",
    "babel-preset-env": "^1.7.0"
  },
  "resolutions": {
    "babel-core": "7.0.0-bridge.0"
  }

I have the same issue, and anyhow still unable to solve it. any help?

9:40:51 AM:   1. Build command from Netlify app                             
9:40:51 AM: ────────────────────────────────────────────────────────────────
9:40:51 AM: ​
9:40:51 AM: $ npm run build
9:40:51 AM: npm WARN config production Use `--omit=dev` instead.
9:40:51 AM: > Ride-My-Way@1.0.0 build
9:40:51 AM: > npm run clean && babel lib -d dist --presets env --omit=dev
9:40:51 AM: npm WARN config production Use `--omit=dev` instead.
9:40:51 AM: > Ride-My-Way@1.0.0 clean
9:40:51 AM: > rm -rf dist
9:40:51 AM: sh: 1: babel: not found
9:40:51 AM: ​
9:40:51 AM:   "build.command" failed                                        
9:40:51 AM: ────────────────────────────────────────────────────────────────
9:40:51 AM: ​
9:40:51 AM:   Error message
9:40:51 AM:   Command failed with exit code 127: npm run build (https://ntl.fyi/exit-code-127)
9:40:51 AM: ​
9:40:51 AM:   Error location
9:40:51 AM:   In Build command from Netlify app:
9:40:51 AM:   npm run build
9:40:51 AM: ​
9:40:51 AM:   Resolved config
9:40:51 AM:   build:
9:40:51 AM:     command: npm run build
9:40:51 AM:     commandOrigin: ui
9:40:51 AM:     environment:
9:40:51 AM:       - JWT_KEY
9:40:51 AM:       - NETLIFY_GRAPH_TOKEN
9:40:51 AM:       - NPM_CONFIG_PRODUCTION
9:40:51 AM:       - ONEGRAPH_AUTHLIFY_TOKEN
9:40:51 AM:       - PORT
9:40:51 AM:     publish: /opt/build/repo/dist
9:40:51 AM:     publishOrigin: ui
9:40:51 AM: Caching artifacts
9:40:51 AM: Started saving node modules
9:40:51 AM: Finished saving node modules
9:40:51 AM: Started saving build plugins
9:40:51 AM: Finished saving build plugins
9:40:51 AM: Started saving corepack cache
9:40:51 AM: Finished saving corepack cache
9:40:51 AM: Started saving pip cache
9:40:51 AM: Finished saving pip cache
9:40:51 AM: Started saving emacs cask dependencies
9:40:51 AM: Finished saving emacs cask dependencies
9:40:51 AM: Started saving maven dependencies
9:40:51 AM: Finished saving maven dependencies
9:40:51 AM: Started saving boot dependencies
9:40:52 AM: Finished saving boot dependencies
9:40:52 AM: Started saving rust rustup cache
9:40:52 AM: Finished saving rust rustup cache
9:40:52 AM: Started saving go dependencies
9:40:52 AM: Finished saving go dependencies
9:40:52 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:40:52 AM: Failing build: Failed to build site
9:40:53 AM: Finished processing build request in 1m14.901s

here is my package.json

{
  "name": "xxxx",
  "version": "1.0.0",
  "description": "xxxxxxxxx",
  "main": "index.js",
  "scripts": {
    "lint": "eslint ./lib/index.js",
    "postinstall": "npm run build",
    "start": "babel-node dist/index.js",
    "dev": "npm run clean && babel-node ./lib/index.js --presets env",
    "test": "mocha ./lib/test/ --recursive --compilers js:babel-register --exit",
    "build": "npm run clean && babel lib -d dist --presets env",
    "clean": "rm -rf dist"
  },
  "author": "xxxxx",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "babel-register": "^6.26.0",
    "@babel/core": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "chai": "^4.1.2",
    "dotenv": "^6.2.0",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.4.0",
    "mocha": "^5.2.0",
    "supertest": "^3.1.0"
  },
  "dependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "@babel/core": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "aglio": "^2.3.0",
    "bcrypt": "^5.0.1",
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.3.0",
    "morgan": "^1.9.1",
    "multer": "^1.4.0",
    "pg": "^7.4.3"
  },
  "engines": {
    "node": "^4.7.0",
    "npm": "^5.5.1"
  },
  "resolutions": {
    "babel-core": "^6.26.3"
  }
}

Hi @fredneutron :wave:t6: ,

Welcome to the forums thanks so much for reaching out. Please give this resource a read?

If that does not help please share your site name/slug and your build setting.

my site name is https://taupe-melba-6c9a15.netlify.app/

and here is my build setting

Try using npx babel instead of babel in your command.

@hrishikesh
I just tried it now, and it is the exact error that babel was not found, so it is trying to install it but ended up installing the wrong one.

here is my package.json

{
  "name": "xxxx",
  "version": "1.0.0",
  "description": "xxxxxx",
  "main": "index.js",
  "scripts": {
    "lint": "eslint ./lib/index.js",
    "postinstall": "npm run build",
    "start": "npx babel-node dist/index.js",
    "dev": "npm run clean && npx babel-node ./lib/index.js",
    "test": "mocha ./lib/test/ --recursive --compilers js:babel-register --exit",
    "build": "npm run clean && npx babel lib -d dist --presets=@babel/preset-env",
    "clean": "rm -rf dist"
  },
  "author": "Babatunde Adelabu",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.21.0",
    "@babel/core": "^7.8.7",
    "@babel/node": "^7.20.7",
    "@babel/preset-env": "^7.8.7",
    "@babel/register": "^7.21.0",
    "chai": "^4.1.2",
    "dotenv": "^6.2.0",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.4.0",
    "mocha": "^5.2.0",
    "supertest": "^3.1.0"
  },
  "dependencies": {
    "@babel/cli": "^7.21.0",
    "@babel/core": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "aglio": "^2.3.0",
    "bcrypt": "^5.0.1",
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.3.0",
    "morgan": "^1.9.1",
    "multer": "^1.4.0",
    "pg": "^7.4.3"
  },
  "engines": {
    "node": "^4.7.0",
    "npm": "^5.5.1"
  }
}

and here is the build log

1:56:51 PM: > Ride-My-Way@1.0.0 postinstall
1:56:51 PM: > npm run build
1:56:51 PM: npm WARN config production Use `--omit=dev` instead.
1:56:51 PM: > Ride-My-Way@1.0.0 build
1:56:51 PM: > npm run clean && npx babel lib -d dist --presets=@babel/preset-env
1:56:51 PM: npm WARN config production Use `--omit=dev` instead.
1:56:51 PM: > Ride-My-Way@1.0.0 clean
1:56:51 PM: > rm -rf dist
1:56:52 PM: npm WARN config production Use `--omit=dev` instead.
1:56:53 PM: npm WARN exec The following package was not found and will be installed: babel@6.23.0
1:56:53 PM: npm WARN deprecated babel@6.23.0: In 6.x, the babel package has been deprecated in favor of babel-cli. Check https://opencollective.com/babel to support the Babel maintainers
1:56:53 PM: You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
1:56:53 PM: Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.
1:56:53 PM:     npm uninstall -g babel
1:56:53 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
1:56:53 PM:     npm install --save-dev babel-cli
1:56:53 PM: See http://babeljs.io/docs/usage/cli/ for setup instructions.
1:56:53 PM: npm ERR! code 1
1:56:53 PM: npm ERR! path /opt/build/repo
1:56:53 PM: npm ERR! command failed
1:56:53 PM: npm ERR! command sh -c -- npm run build
1:56:53 PM: npm ERR! A complete log of this run can be found in:
1:56:53 PM: npm ERR!     /opt/buildhome/.npm/_logs/2023-03-05T12_55_39_510Z-debug-0.log
1:56:53 PM: Error during npm install
1:56:53 PM: Build was terminated: Build script returned non-zero exit code: 1
1:56:53 PM: Failing build: Failed to build site
1:56:55 PM: Finished processing build request in 1m19.991s

As this mentions, did you try installing babel-cli?

@hrishikesh

Yeah, I did. it was still the same so I uninstalled it.

Please share a reproduction repo.

@hrishikesh here is the link to the repo
https://github.com/fredneutron/Ride-My-Way/tree/deploy-fix

hi @fredneutron

I forked that repo and was able to deploy branch deploy-fix. What are the steps I need to run to reproduce the same error you have?

Thanks

Hi @gualter
There is no particular step to it, I have already provided every detail on the issue. I am able to deploy fine on my localhost, the only problem is on Netlify, maybe you can share your steps so I can cross-check and see what I’m missing.

Thanks

@fredneutron

I just forked your repo, then created a new site on Netlify, set the production branch as deploy-fix and it worked. What happens when you follow this steps?

@gualter
I just tried it again now, it is deploying now. one other issue, how do I publish the main in my package.json file?

thanks

hi @fredneutron

You want to publish this repo on your site? You need to have an index.html for the site to render:

The site already has an index.js, take a look at my deployment that I mentioned:

https://dainty-halva-33e2f5.netlify.app/index.js

Hope this helps!

thanks @gualter

I fixed it now, I change the publish directory to the directory of the index.html, the page is working fine.

thanks for your help.

1 Like

awesome! glad I could help

1 Like