'bash: yarn: command not found' error

I’m having a build issue with my personal website.

Here’s the full build log with the error.
It says yarn: command not found, Command failed with exit code 127: yarn build.
I’m not sure why yarn build command is the problem, but it works fine on my local terminal and that’s the command I use normally.
publish: /opt/build/repo/build >> I’m also not sure about this line since there is no opt folder or repo file in my file or in netlify.toml at all.

I’ve looked into some other topics but none of the solution helped.
I’d really appreciate if anyone can give a hand on this!!!

12:17:09 AM: Build ready to start
12:17:10 AM: build-image version: 3031d4c9e432fd7016f6279fc9ad706f9205d845
12:17:10 AM: build-image tag: v3.3.17
12:17:10 AM: buildbot version: 1f35b3abd6e2bf5230d8edf68072840fdec1513f
12:17:11 AM: Fetching cached dependencies
12:17:11 AM: Failed to fetch cache, continuing with build
12:17:11 AM: Starting to prepare the repo for build
12:17:11 AM: No cached dependencies found. Cloning fresh repo
12:17:11 AM: git clone GitHub - stone-skipper/smlweb: sml website in process
12:17:30 AM: Preparing Git Reference refs/heads/gh-pages
12:17:32 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘build’ versus ‘build/’ in the Netlify UI
12:17:32 AM: Starting build script
12:17:32 AM: Installing dependencies
12:17:32 AM: Python version set to 2.7
12:17:33 AM: v12.18.0 is already installed.
12:17:34 AM: Now using node v12.18.0 (npm v6.14.4)
12:17:34 AM: Started restoring cached build plugins
12:17:34 AM: Finished restoring cached build plugins
12:17:34 AM: Attempting ruby version 2.7.1, read from environment
12:17:36 AM: Using ruby version 2.7.1
12:17:36 AM: Using PHP version 5.6
12:17:36 AM: 5.2 is already installed.
12:17:36 AM: Using Swift version 5.2
12:17:36 AM: Started restoring cached go cache
12:17:36 AM: Finished restoring cached go cache
12:17:36 AM: go version go1.14.4 linux/amd64
12:17:36 AM: go version go1.14.4 linux/amd64
12:17:36 AM: Installing missing commands
12:17:36 AM: Verify run directory
12:17:37 AM: ​
12:17:37 AM: ┌─────────────────────────────┐
12:17:37 AM: │ Netlify Build │
12:17:37 AM: └─────────────────────────────┘
12:17:37 AM: ​
12:17:37 AM: ❯ Version
12:17:37 AM: @netlify/build 2.0.10
12:17:37 AM: ​
12:17:37 AM: ❯ Flags
12:17:37 AM: deployId: 5ef4bff45ac5bc83467b5a06
12:17:37 AM: mode: buildbot
12:17:37 AM: ​
12:17:37 AM: ❯ Current directory
12:17:37 AM: /opt/build/repo
12:17:37 AM: ​
12:17:37 AM: ❯ Config file
12:17:37 AM: No config file was defined: using default values.
12:17:37 AM: ​
12:17:37 AM: ❯ Context
12:17:37 AM: production
12:17:37 AM: ​
12:17:37 AM: ❯ Loading plugins
12:17:37 AM: - netlify-plugin-image-optim@0.3.0 from Netlify app
12:17:37 AM: - netlify-plugin-hashfiles@4.0.2 from Netlify app
12:17:38 AM: ​
12:17:38 AM: ┌────────────────────────────────┐
12:17:38 AM: │ 1. Build command from settings │
12:17:38 AM: └────────────────────────────────┘
12:17:38 AM: ​
12:17:38 AM: $ yarn build
12:17:38 AM: bash: yarn: command not found
12:17:39 AM: ​
12:17:39 AM: ┌─────────────────────────────┐
12:17:39 AM: │ “build.command” failed │
12:17:39 AM: └─────────────────────────────┘
12:17:39 AM: ​
12:17:39 AM: Error message
12:17:39 AM: Command failed with exit code 127: yarn build
12:17:39 AM: ​
12:17:39 AM: Error location
12:17:39 AM: In Build command from settings:
12:17:39 AM: yarn build
12:17:39 AM: ​
12:17:39 AM: Resolved config
12:17:39 AM: build:
12:17:39 AM: command: yarn build
12:17:39 AM: publish: /opt/build/repo/build
12:17:39 AM: plugins:
12:17:39 AM: - inputs: {}
12:17:39 AM: origin: ui
12:17:39 AM: package: netlify-plugin-image-optim
12:17:39 AM: - inputs: {}
12:17:39 AM: origin: ui
12:17:39 AM: package: netlify-plugin-hashfiles
12:17:39 AM: Caching artifacts
12:17:39 AM: Started saving build plugins
12:17:39 AM: Finished saving build plugins
12:17:39 AM: Started saving pip cache
12:17:45 AM: Finished saving pip cache
12:17:45 AM: Started saving emacs cask dependencies
12:17:45 AM: Finished saving emacs cask dependencies
12:17:45 AM: Started saving maven dependencies
12:17:45 AM: Finished saving maven dependencies
12:17:45 AM: Started saving boot dependencies
12:17:45 AM: Finished saving boot dependencies
12:17:45 AM: Started saving go dependencies
12:17:45 AM: Finished saving go dependencies
12:17:48 AM: Error running command: Build script returned non-zero exit code: 1
12:17:48 AM: Failing build: Failed to build site
12:17:48 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1
12:17:48 AM: Finished processing build request in 37.947101987s

1 Like

Does your repo have a yarn.lock file?

Yes there is one. I also tried deleting node modules and yarn.lock and reinstalling everything as someone suggested in the similar question.

could you post your package.json file please?

{
  "name": "smlweb",
  "homepage": "http://stone-skipper.github.io/smlweb",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/core": "^7.10.3",
    "@material-ui/core": "^4.0.2",
    "@material-ui/icons": "^4.0.1",
    "@svgr/webpack": "4.3.3",
    "@types/react": "^16.9.41",
    "@types/react-dom": "^16.9.8",
    "@types/styled-components": "^4.4.0",
    "@typescript-eslint/eslint-plugin": "^2.10.0",
    "@typescript-eslint/parser": "^2.10.0",
    "babel-eslint": "10.1.0",
    "babel-jest": "^24.9.0",
    "babel-loader": "^8.1.0",
    "babel-plugin-named-asset-import": "^0.3.6",
    "babel-preset-react-app": "^9.1.2",
    "camelcase": "^5.3.1",
    "case-sensitive-paths-webpack-plugin": "2.3.0",
    "css-loader": "^3.6.0",
    "dotenv": "8.2.0",
    "dotenv-expand": "5.1.0",
    "eslint": "^6.6.0",
    "eslint-config-react-app": "^5.2.1",
    "eslint-loader": "3.0.3",
    "eslint-plugin-flowtype": "4.6.0",
    "eslint-plugin-import": "2.20.1",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "7.19.0",
    "eslint-plugin-react-hooks": "^1.6.1",
    "file-loader": "4.3.0",
    "fs-extra": "^8.1.0",
    "html-webpack-plugin": "^4.3.0",
    "identity-obj-proxy": "3.0.0",
    "jest": "24.9.0",
    "jest-environment-jsdom-fourteen": "1.0.1",
    "jest-resolve": "24.9.0",
    "jest-watch-typeahead": "0.4.2",
    "lottie-react-web": "^2.1.4",
    "lqip-react": "^1.0.1",
    "mini-css-extract-plugin": "^0.9.0",
    "netlify-cli": "^2.54.0",
    "optimize-css-assets-webpack-plugin": "5.0.3",
    "pnp-webpack-plugin": "1.6.4",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "postcss-normalize": "8.0.1",
    "postcss-preset-env": "6.7.0",
    "postcss-safe-parser": "4.0.1",
    "react": "^16.13.1",
    "react-app-polyfill": "^1.0.6",
    "react-dev-utils": "^10.2.1",
    "react-dom": "^16.13.1",
    "react-feather": "^1.1.6",
    "react-hotjar": "^2.2.0",
    "react-lazy-load": "^3.0.13",
    "react-lazyload": "^2.6.8",
    "react-lottie": "^1.2.3",
    "react-player": "^1.15.2",
    "react-router-dom": "^5.0.1",
    "react-scripts": "^3.4.1",
    "react-slideshow-image": "^1.4.2",
    "react-transition-group": "^4.1.1",
    "resolve": "1.15.0",
    "resolve-url-loader": "3.1.1",
    "sass-loader": "^8.0.2",
    "semver": "6.3.0",
    "style-loader": "^1.2.1",
    "styled-components": "^4.3.1",
    "terser-webpack-plugin": "2.3.5",
    "ts-pnp": "1.1.6",
    "typescript": "^3.9.5",
    "url-loader": "^4.1.0",
    "webpack-manifest-plugin": "2.2.0",
    "workbox-webpack-plugin": "4.3.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "eslintConfig": {
    "extends": "airbnb",
    "rules": {
      "react/prefer-stateless-function": 0,
      "react/jsx-filename-extension": 0,
      "react/jsx-one-expression-per-line": 0
    },
    "env": {
      "browser": true
    }
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/preset-env": "^7.10.3",
    "@babel/preset-react": "^7.10.1",
    "clean-webpack-plugin": "^3.0.0",
    "eslint-plugin-prettier": "^3.0.1",
    "gh-pages": "^2.2.0",
    "html-loader": "^1.1.0",
    "image-webpack-loader": "^6.0.0",
    "imagemin-jpegtran": "^7.0.0",
    "imagemin-webpack": "^5.1.1",
    "lqip-loader": "^2.2.0",
    "node-sass": "^4.14.1",
    "prettier": "1.16.4",
    "pretty-quick": "^1.10.0",
    "uglify-js-brunch": "^2.10.0",
    "webpack-cli": "^3.3.12"
  },
  "prettier": {
    "tabWidth": 2,
    "semi": false,
    "singleQuote": true
  },
  "jest": {
    "roots": [
      "<rootDir>/src"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts"
    ],
    "setupFiles": [
      "react-app-polyfill/jsdom"
    ],
    "setupFilesAfterEnv": [],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
      "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jest-environment-jsdom-fourteen",
    "transform": {
      "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "modulePaths": [],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ],
    "watchPlugins": [
      "jest-watch-typeahead/filename",
      "jest-watch-typeahead/testname"
    ]
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ]
  }
}

Here it is! thanks for taking the time :slight_smile:

So the problem is here that you are telling Netlify to run the command “yarn build” but:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },

yarn is only available in our build environment when a yarn.lock file exists in the root of your repo (or in the base directory, if set), OR if you add it in package.json and THAT file exists in the root of your repo (or in the base directory, if set)

You might also find this generic debugging information useful.

This Support Guide contains a ton of useful debugging tips.

If you want to use any yarn command in your build process then included yarn.lock in your root directory. Even empty file of yarn.lock will work fine.