gatsby-cli broken after upgrade: Error: Cannot find module './create-cli'

Created on 29 Dec 2018  Â·  27Comments  Â·  Source: gatsbyjs/gatsby

Description

Gatsby CLI not working after upgrade.

Steps to reproduce

npm i -g gatsby-cli

Expected result

gatsby-cli should work normally after upgrade

Actual result

screen shot 2018-12-28 at 6 29 44 pm

Error: Cannot find module './create-cli'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/gatsby-cli/lib/index.js:70:19)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

Environment

Run gatsby info --clipboard in your project directory and paste the output here. Not working? You may need to update your global gatsby-cli - npm install -g gatsby-cli

gatsby info --clipboard does not work now. Unable to run gatsby-cli.

needs more info

Most helpful comment

Quick followup. The only thing that fixed this issue for me was reinstalling node.js entirely. After that I reinstalled gatsby-cli and everything started working again. @sidharthachatterjee I did this before seeing your message. Not sure if that output would reflect the state it was in while the error was happening as it's fixed now.

All 27 comments

+1

@systemlevel and @Fabiantjoeaon i've updated the cli tool using npm i -g gatsby-cli just now.
I'm now at version 2.4.8 as we speak.
Fired up a wsl machine running ubuntu and did the same. On both windows 10 and wsl i'm running version 2.4.8.
As you can see the bellow, the first image is the wsl and the second windows 10. Before hand pardon me for the windows 10 screenshot as the computer i'm currently working is a work computer not a personal one.
wsl_gatsby_version
win_10_gatsby_version

Issuing gatsby develop and gatsby build && gatsby serve provide the same result. No errors are thrown.
As you can see bellow
wsl_develop_outp
win10_develop_outp

Regarding your issue, probably something might have gone wrong during the download/installation process. What i would like for both of you is to uninstall the cli issuing npm uninstall -g gatsby-cli or if you're using yarn yarn global remove gatsby-cli. And then re-install the package. And provide some feedback if the issue is resolved or persists.

Apologies that you're seeing this @systemlevel

I can't reproduce this with the latest install and would need a few more details to understand what is causing this.

Can you please post details about your current environment including your Node version, installed version of gatsby-cli and what /usr/local/lib/node_modules/gatsby-cli/lib looks like (output of ls will do)

Quick followup. The only thing that fixed this issue for me was reinstalling node.js entirely. After that I reinstalled gatsby-cli and everything started working again. @sidharthachatterjee I did this before seeing your message. Not sure if that output would reflect the state it was in while the error was happening as it's fixed now.

I guess this might've had to do with something breaking while installing gatsby-cli in the first place. I'm glad it's working for you now @systemlevel

Closing this in the mean time but please feel free to reopen if this occurs again

I have the same issue right now. Running node v8.12.0 with gatsby v2.4.8.

ls /usr/local/lib/node_modules/gatsby-cli/lib:
in index.js init-starter.js reporter

@victorbjorklund That directory should include create-cli.js

This is _strange_. Can you post some details about your env? And did were there any errors in the console when you upgraded to 2.4.8?

I have the exact same issue. I updated gatsby to v2.4.11 (node v10.15.1) and now I keep getting "Cannot find module './create-cli'" and in /usr/local/lib/node_modules/gatsby-cli/lib there's only index.js, init-starter.js and reporter.

@irenedemas super strange!

Here's the path to that file (with that version) https://unpkg.com/[email protected]/lib/create-cli.js

I also just installed gatsby-cli (globally) to validate and the file is there as expected, so this is a strange one.

Could you paste the output of npx gatsby info --clipboard? Also, could you share more info about the steps you've taken thus far? Were there any errors installing gatsby-cli?

The input of npx gatsby info --clipboard is Cannot find module './create-cli'

And no, there were no errors installing gatsby-cli. Actually I uninstalled it and installed it again and I still have the same problem.

@irenedemas if you don't mind i would like for you to do one thing. As you're using npm

npm cache clean

What this will do is purge the global npm cache.
Install gatsby cli again using the following command sudo npm install -g gatsby-cli assuming you are running ubuntu, if not adjust for your setup.

My reasoning behind this, because on a old machine i had laying around, this issue popped up and no matter how many ways i went about it, the result was the same you're experiencing, which is according to a bit of investigation, npm was going for the cached version and not for the remote version and if the cached version had some issues, then it would propagate it.

Feel free to provide feedback

I tried doing this and I still get the same Cannot find module './create-cli'

one more quick question, are you running osx or a linux distribution?

OSX

Update: I tried npx gatsby info --clipboard and this worked now. The input is:

System:
    OS: macOS 10.14.3
    CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.1 - /usr/local/bin/node
    npm: 6.4.1 - /usr/local/bin/npm
  Languages:
    Python: 2.7.14 - /usr/local/bin/python
  Browsers:
    Chrome: 72.0.3626.109
    Firefox: 34.0.5
    Safari: 12.0.3
  npmGlobalPackages:
    gatsby-cli: 2.4.11

@irenedemas wow, that's really good news. It means that gatsby is installed correctly. Did you do anything else? Also just to be sure, create a dummy folder somewhere and issue npx gatsby new my-hello-world-starter https://github.com/gatsbyjs/gatsby-starter-hello-world to confirm that everything is working correctly if you don't mind

I did that and npx gatsby new works (tried with the hello world starter and a couple more and they all work). However, when I try to npm run develop I get this error: npm ERR! missing script: develop

@irenedemas did you cd to the starter directory? Or could you paste the contents of that package.json?

I did cd to the starter directory and the contents of the package.json are:

{
  "name": "ueno-gatsby-starter",
  "description": "Opinionated Gatsby starter by Ueno",
  "version": "1.0.0",
  "license": "MIT",
  "keywords": [
    "gatsby",
    "starter",
    "react",
    "typescript",
    "gatsby-starter",
    "ueno"
  ],
  "contributors": [
    "Birkir Gudjonsson <[email protected]>",
    "Jérémy Barbet <[email protected]>"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/ueno-llc/ueno-gatsby-starter"
  },
  "scripts": {
    "dev": "gatsby develop",
    "build": "gatsby build",
    "start": "gatsby serve --port ${PORT:-3000}",
    "clean": "rimraf .cache public",
    "lint": "npm run tslint && npm run stylelint",
    "tslint": "tslint --fix 'src/**/*.{ts,tsx}' -p .",
    "stylelint": "stylelint 'src/**/*.scss' --syntax scss"
  },
  "dependencies": {
    "gatsby": "2.0.91",
    "gatsby-image": "2.0.26",
    "gatsby-plugin-config": "1.0.7",
    "gatsby-plugin-layout": "1.0.11",
    "gatsby-plugin-manifest": "2.0.13",
    "gatsby-plugin-react-helmet": "3.0.5",
    "gatsby-plugin-react-svg": "2.0.0",
    "gatsby-plugin-sharp": "2.0.17",
    "gatsby-plugin-typescript": "2.0.3",
    "gatsby-plugin-ueno": "2.0.1",
    "gatsby-source-graphql-universal": "^2.0.4",
    "gatsby-transformer-sharp": "2.1.10",
    "gsap": "2.0.2",
    "gsap-tools": "1.0.9",
    "lodash": "4.17.11",
    "react": "16.8.0",
    "react-dom": "16.8.0",
    "react-helmet": "5.2.0"
  },
  "devDependencies": {
    "@babel/core": "7.2.2",
    "@types/gsap": "1.20.1",
    "@types/lodash": "4.14.119",
    "@types/node": "10.12.18",
    "@types/react": "16.8.2",
    "@types/react-dom": "16.8.0",
    "@types/react-helmet": "5.0.8",
    "@ueno/stylelint-config": "1.1.2",
    "@ueno/tslint-config": "1.0.3",
    "rimraf": "2.6.3",
    "stylelint": "9.9.0",
    "tslint": "5.12.1",
    "tslint-react": "3.6.0",
    "typescript": "3.3.1"
  }
}

@irenedemas which option did you go when creating the new website as described here, you installed ueno package or went on with the alternative?
Also do one more thing if you don't mind

  • Create a new folder somewhere and inside it issue npx gatsby new my-default-starter https://github.com/gatsbyjs/gatsby-starter-default.
  • Change into the newly created directory and issue gatsby develop or npm run develop up to you.
    And paste the output of the said command here.
    Sounds good?
    Side note:
    I've just installed this starter using the alternative way of setting it up and issuing npm run develop or gatsby develop inside that starter it will compile fine, but results in a error on opening up http://localhost:8000. I'm currently creating a issue in their repo in order to see what's wrong and how to solve it

I used the official npx gatsby new ueno-test https://github.com/ueno-llc/ueno-gatsby-starter

Re npx gatsby new my-default-starter https://github.com/gatsbyjs/gatsby-starter-default + 'gatsby develop' and it works!

That said, if I try to gatsby develop a started I already had installed (https://github.com/irenedemas/portfolio-irene) I get the following error. I've been using Gatsby for months and this didn't happen until this update so I guess it's related to it.

error UNHANDLED EXCEPTION


  Error: Module did not self-register.

  - loader.js:718 Object.Module._extensions..node
    internal/modules/cjs/loader.js:718:18

  - loader.js:599 Module.load
    internal/modules/cjs/loader.js:599:32

  - loader.js:538 tryModuleLoad
    internal/modules/cjs/loader.js:538:12

  - loader.js:530 Function.Module._load
    internal/modules/cjs/loader.js:530:3

  - loader.js:637 Module.require
    internal/modules/cjs/loader.js:637:17

  - helpers.js:22 require
    internal/modules/cjs/helpers.js:22:18

  - constructor.js:8 Object.<anonymous>
    [portfolioirene]/[sharp]/lib/constructor.js:8:15

  - loader.js:689 Module._compile
    internal/modules/cjs/loader.js:689:30

  - loader.js:700 Object.Module._extensions..js
    internal/modules/cjs/loader.js:700:10

  - loader.js:599 Module.load
    internal/modules/cjs/loader.js:599:32

  - loader.js:538 tryModuleLoad
    internal/modules/cjs/loader.js:538:12

  - loader.js:530 Function.Module._load
    internal/modules/cjs/loader.js:530:3

  - loader.js:637 Module.require
    internal/modules/cjs/loader.js:637:17

  - helpers.js:22 require
    internal/modules/cjs/helpers.js:22:18

  - index.js:3 Object.<anonymous>
    [portfolioirene]/[sharp]/lib/index.js:3:15

  - loader.js:689 Module._compile
    internal/modules/cjs/loader.js:689:30


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] develop: `gatsby develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] develop script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


@irenedemas ok! Weird error - guessing that error you just pasted is because you need to re-install node_modules (npm install--may want to remove node_modules folder first). That tends to happen if you try to re-run a project with a different version of Node apparently.

Second thing--you mentioned you were using the hello-world starter (which does contain a develop script!) but the package.json indicates you used the ueno starter--which is totally fine! The script in that case would be npm run dev.

If you run into other issues here, I'd happily offer to work on a pairing session to help you iron out these issues.

It's unfortunate you've had so many--hopefully we can get these all ironed out. Thanks for bearing with us!

@irenedemas
Hey,

On a side note regarding ueno-gatsby-starter you have to do:

npm install -g gatsby-cli
gatsby new my-app "https://github.com/ueno-llc/ueno-gatsby-starter#master --recursive"

The --recursive argument is important because we use a git submodule for one of the folder inside the repository, and without it, the folder is not clone. You can find the full documentation here.

I have the exact same problem:

running yarn dev results in:

alex@SURFACE-ALEX C:\Users\alex\vermehrung
$ yarn dev
yarn run v1.13.0
$ cross-env HASURA_GRAPHQL_URL=https://api.vermehrung.apflora.ch/v1alpha1/graphql gatsby develop
internal/modules/cjs/loader.js:611
    throw err;
    ^

Error: Cannot find module 'gatsby-cli'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:609:15)
    at Function.Module._load (internal/modules/cjs/loader.js:535:25)
    at Module.require (internal/modules/cjs/loader.js:663:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\alex\vermehrung\node_modules\gatsby\dist\bin\gatsby.js:4:1)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)
error Command failed with exit code 1.

Running npx gatsby info --clipboard results in: Cannot find module 'gatsby-cli.

I have repeatedly:

  • removed yarn.lock
  • removed then reinstalled node_modules
  • uninstalled gatsby-cli
  • cleaned npm cache (global installs are done using npm, local using yarn)

I am using:

  • Windows 10 up to date
  • node v11.9.0

I am badly struck as none of my gatsby projects run anymore :-(

Hm. gatsby develop by itself _does_ run.

My dev script looks like this: cross-env HASURA_GRAPHQL_URL=https://api.vermehrung.apflora.ch/v1alpha1/graphql gatsby develop

This so far has worked a few hundred times. But not anymore.

@DSchau I am really sorry for the delay in answering. Now when I use a new starter (e.g. ueno's) everything works but when I try to gatsby develop my previous project I get this error:

success delete html files from previous builds — 0.016 s
success open and validate gatsby-config.js — 0.007 s
error UNHANDLED REJECTION


  Error: Unable to find plugin "gatsby-remark-images"

  - load-plugins.js:96 resolvePlugin
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:96:11

  - load-plugins.js:147 processPlugin
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:147:27

  - load-plugins.js:130
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:130:35

  - Array.forEach

  - load-plugins.js:129 processPlugin
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:129:40

  - load-plugins.js:168
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:168:28

  - Array.forEach

  - load-plugins.js:167 _callee$
    [portfolioirene]/[gatsby]/dist/bootstrap/load-plugins.js:167:28

  - new Promise

Any ideas on how to fix it or where I should look?

Thank you and sorry again.

What worked for me:

NPM Version: 6.13.4
Node version: v12.16.1

  • Uninstall gatsby-cli 2.12.31 and install version 2.12.21
  • Install detect-port as mentioned before

(While I havent tried it out, installing detect port only should work too.)
```
npm uninstall -g gatsby-cli
npm install -g [email protected]
npm i -g detect-port

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andykais picture andykais  Â·  3Comments

Oppenheimer1 picture Oppenheimer1  Â·  3Comments

jimfilippou picture jimfilippou  Â·  3Comments

dustinhorton picture dustinhorton  Â·  3Comments

3CordGuy picture 3CordGuy  Â·  3Comments