Gatsby: Gatsby Build Error

Created on 17 May 2018  Â·  7Comments  Â·  Source: gatsbyjs/gatsby

Description

Unable to re-run gatsby develop after closing my git bash

Steps to reproduce

Clear steps describing how to reproduce the issue.

Expected result

What should happen?

Actual result

USer@Asus MINGW64 /c/usr/local/yuhan/node_modules/gatsby/node_modules/.bin
$ gatsby develop
index.js develop

Start development server. Watches files, rebuilds, and hot reloads if something changes

Options:
--verbose Turn on verbose output [boolean] [default: false]
--no-color Turn off the color in output [boolean] [default: false]
-H, --host Set host. Defaults to localhost [string] [default: "localhost"]
-p, --port Set port. Defaults to 8000 [string] [default: "8000"]
-o, --open Open the site in your browser for you. [boolean]
-S, --https Use HTTPS. See https://www.gatsbyjs.org/docs/local-https/ as a guide [boolean]
-c, --cert-file Custom HTTPS cert file (relative path; also required: --https, --key-file). See https://www.gatsbyjs.org/docs/local-https/ [string] [default: ""]
-k, --key-file Custom HTTPS key file (relative path; also required: --https, --cert-file). See https://www.gatsbyjs.org/docs/local-https/ [string] [default: ""]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]

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

Environment

  • Gatsby version (npm list gatsby):
  • gatsby-cli version (gatsby --version):
  • Node.js version:
  • Operating System:

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

question or discussion

Most helpful comment

Could you check if you have a package.json in your project folder, with content:

{
  ...rest of code,
  "dependencies": {
    "gatsby": "^1.9.xxx"
  },
  "scripts": {
    "develop": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve"
  },
  ...rest of code
}

If you do, you can run:

  • rm -rf node_modules
  • npm install or yarn (if you use yarn instead of npm)
  • npm run develop or yarn develop. This will run Gatsby that’s installed on your node_modules folder

The above will work even if you don’t have gatsby-cli installed globally on your system.

All 7 comments

You need to run gatsby develop from your website directory - in pasted terminal output you are trying to run it from /c/usr/local/yuhan/node_modules/gatsby/node_modules/.bin which seems wrong here.

Appreciate the help

I have run it on:

USer@Asus MINGW64 /c/usr/local/yuhan
$ gatsby develop
module.js:549
throw err;
^

Error: Cannot find module 'C:\usr\local\gatsby\dist\bin\gatsby.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

Removing all node_modules of gatsby-cli doesn't help either.

Could you check if you have a package.json in your project folder, with content:

{
  ...rest of code,
  "dependencies": {
    "gatsby": "^1.9.xxx"
  },
  "scripts": {
    "develop": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve"
  },
  ...rest of code
}

If you do, you can run:

  • rm -rf node_modules
  • npm install or yarn (if you use yarn instead of npm)
  • npm run develop or yarn develop. This will run Gatsby that’s installed on your node_modules folder

The above will work even if you don’t have gatsby-cli installed globally on your system.

It worked! I am new to node hence this seems very amateur but do I 're-run' the script with 'npm run develop?'

Yup, you do npm run develop every time you want to spin up a development server.

gatsby develop should work too if you have gatsby-cli installed globally on your system.

To check: run npm ls -g --depth=0. This will list the global packages you have installed. If gatsby-cli doesn’t show up there, do npm i -g gatsby-cli to install it globally.

It looks like this is resolved. Thanks everyone :)

I'm also occuring the same issue. Anything didn't worked for me and getting the 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jivings picture Jivings  Â·  112Comments

antoinerousseau picture antoinerousseau  Â·  139Comments

kripod picture kripod  Â·  74Comments

cusspvz picture cusspvz  Â·  128Comments

rchrdnsh picture rchrdnsh  Â·  81Comments