Gatsby <build> can only be run for a gatsby site. Either the current working directory does not contain a valid package.json or 'gatsby' is not specified as a dependency

Hello someone help me with this my Gatsby site has been running okay for a while but now I’m getting issues I can’t build & deploy locally also on Github below is the error I’m getting when running “Netlify Build” locally & Also “Gatsby Build” on Netlify.

gatsby build

Build a Gatsby project.

Options:
–verbose Turn on verbose output [boolean] [default: false]
–no-color, --no-colors Turn off the color in output [boolean] [default: false]
–json Turn on the JSON logger [boolean] [default: false]
–prefix-paths Build site with link paths prefixed with the pathPrefix value in gatsby-config.js. Default is env.PREFIX_PATHS
or false. [boolean] [default: false]
–no-uglify Build site without uglifying JS bundles (for debugging). [boolean] [default: false]
–profile Build site with react profiling (this can add some additional overhead). See https://reactjs.org/docs/profiler
[boolean] [default: false]
–graphql-tracing Trace every graphql resolver, may have performance implications [boolean] [default: false]
–open-tracing-config-file Tracer configuration file (OpenTracing compatible). See Performance Tracing [string]
-h, --help Show help [boolean]
-v, --version Show the version of the Gatsby CLI and the Gatsby package in the current project [boolean]

ERROR

gatsby can only be run for a gatsby site.
Either the current working directory does not contain a valid package.json or ‘gatsby’ is not specified as a dependency

could you share your package.json and a screenshot of your build settings, please?

I fixed the error and it disappeared now this is what I’m getting

9:32:10 AM: $ yarn build
9:32:11 AM: yarn run v1.22.10
9:32:11 AM: $ gatsby build
9:32:11 AM: /bin/sh: 1: gatsby: not found
9:32:11 AM: error Command failed with exit code 127.
9:32:11 AM: info Visit yarn run | Yarn for documentation about this command.
9:32:11 AM: ​
9:32:11 AM: ────────────────────────────────────────────────────────────────
9:32:11 AM: “build.command” failed
9:32:11 AM: ────────────────────────────────────────────────────────────────
9:32:11 AM: ​
9:32:11 AM: Error message
9:32:11 AM: Command failed with exit code 127: yarn build
9:32:11 AM: ​
9:32:11 AM: Error location
9:32:11 AM: In build.command from netlify.toml:
9:32:11 AM: yarn build

This is my package.json file

"dependencies": {
    "@babel/plugin-transform-spread": "^7.12.1",
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material/button": "^13.0.0",
    "@mui/icons-material": "^5.4.1",
    "@mui/material": "^5.4.1",
    "@sideway/address": "^4.1.2",
    "@typeform/embed-react": "^1.1.1",
    "bootstrap": "^5.1.0",
    "framer-motion": "^3.3.0",
    "fs.promises": "^0.1.2",
    "gatsby": "^4.7.1",
    "gatsby-image": "^2.11.0",
    "gatsby-plugin-crisp-chat": "^3.2.2",
    "gatsby-plugin-gdpr-cookies": "^2.0.6",
    "gatsby-plugin-google-analytics": "^2.11.0",
    "gatsby-plugin-google-tagmanager": "^3.14.0",
    "gatsby-plugin-hotjar": "^1.1.1",
    "gatsby-plugin-hubspot": "^1.3.5",
    "gatsby-plugin-mailchimp": "^5.2.2",
    "gatsby-plugin-mailgo": "^0.12.2",
    "gatsby-plugin-manifest": "^4.7.0",
    "gatsby-plugin-mdx": "^3.7.0",
    "gatsby-plugin-page-creator": "^3.9.0",
    "gatsby-plugin-quantcast-tag": "^0.1.1",
    "gatsby-plugin-react-helmet": "^3.10.0",
    "gatsby-plugin-robots-txt": "^1.5.5",
    "gatsby-plugin-sharp": "^4.7.0",
    "gatsby-plugin-sitemap": "^4.5.0",
    "gatsby-plugin-theme-ui": "^0.3.5",
    "gatsby-plugin-tidio": "^1.0.5",
    "gatsby-plugin-tidio-chat": "^1.0.0",
    "gatsby-plugin-web-font-loader": "^1.0.4",
    "gatsby-source-filesystem": "^2.11.0",
    "gatsby-transformer-sharp": "^4.7.0",
    "mdb-react-ui-kit": "^1.1.0",
    "mdbreact": "^5.1.0",
    "netlify-cli": "^9.4.2",
    "polished": "^4.1.0",
    "prop-types": "^15.8.1",
    "rc-collapse": "^3.1.0",
    "rc-drawer": "^4.3.0",
    "rc-motion": "^2.4.1",
    "react": "^17.0.1",
    "react-bootstrap": "^1.6.1",
    "react-collapsible": "^2.8.3",
    "react-cookie-banner": "^4.1.0",
    "react-cookie-consent": "^6.2.4",
    "react-cookie-consent-notification": "^1.1.1",
    "react-cookienotice": "^3.7.0",
    "react-custom-scrollbars": "^4.2.1",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "react-hook-form": "^7.12.2",
    "react-icons": "^4.3.1",
    "react-kawaii": "^0.17.0",
    "react-multi-carousel": "^2.6.5",
    "react-netlify-forms": "^1.3.2",
    "react-scroll": "^1.8.1",
    "react-slick": "^0.28.0",
    "react-stickynode": "^3.0.4",
    "sharp": "^0.30.1",
    "styled-components": "^5.3.3",
    "theme-ui": "^0.3.5"
  },
  "devDependencies": {
    "gatsby": "^4.7.1",
    "gatsby-plugin-netlify": "^4.1.0",
    "html-loader": "^2.1.2",
    "prettier": "^2.2.1"
  },
  "keywords": [
    "gatsby"
  ],
  "scripts": {
    "dev": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve"
  }
}

This is my netlify.toml file

[build]
    command = "yarn build"
    publish = "public"
[dev]
    command = "yarn dev"
[[plugins]]
  package = "netlify-plugin-search-index"

These are my build settings.

Hey @JohnMunuve

Could you try moving src from the base directory, and make the publish directory just public.

This didn’t work it just brings other errors I instead changed the build command to gatsby build & yarn run on the netlify.toml file

Hey there, @JohnMunuve :wave:

Can you confirm if you are still encountering issues please?