Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error thrown when using the Gatsby CLI after install - "Error: Cannot find module 'detect-port'" #24325

Closed
mitchellbusby opened this issue May 22, 2020 · 16 comments
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@mitchellbusby
Copy link

Description

When I installed the gatsby CLI, I was unable to run it; it throws this exception in the command line:

image

This is only resolveable by globally installing detect-port, at which point everything is fine. Perhaps a missing dependency that wasn't included?

Steps to reproduce

  1. Install gatsby-cli globally.
  2. Try to create a new site with the Gatsby CLI per the tutorial (or run gatsby -v - any command will cause the failure it seems)
  3. The above error is spat out

Expected result

What should happen?

It should not throw

Actual result

It throws an exception saying that detect-port could not be found.

Environment

System:
OS: macOS 10.15.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.13.0/bin/npm
Languages:
Python: 2.7.17 - /usr/local/bin/python
Browsers:
Chrome: 81.0.4044.138
Edge: 81.0.416.72
Firefox: 74.0.1
Safari: 13.1
npmGlobalPackages:
gatsby-cli: 2.12.31

NB I had to do the above manual install of detect-port to get this to work

@mitchellbusby mitchellbusby added the type: bug An issue or pull request relating to a bug in Gatsby label May 22, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 22, 2020
@lukenetti3
Copy link

This exact same thing happened to me as well.

@ryan-talus
Copy link

ryan-talus commented May 22, 2020

This is currently happening in my builds as well; using the gatsby-cli installed locally in my project's node_modules (by using yarn build instead of gatsby build, in my case) instead of the global install appears to be a workaround because detect-port is already installed (as a way to avoid globally installing detect-port).

@lannonbr
Copy link
Contributor

This is a regression of #24065

Looks like it was an removed from the gatsby-recipes package.json, but it technically is used here in recipes.js of the cli so it should be then re-added to gatsby-cli's package.json.

@valentinradu
Copy link

valentinradu commented May 22, 2020

Same here. One quick fix is to install everything locally:

yarn add gatsby-cli
yarn add detect-port
npx gatsby help

or install detect-port globally:

yarn global add gatsby-cli
yarn global add detect-port
gatsby help

@ruie
Copy link

ruie commented May 22, 2020

Same here. One quick fix is to install everything locally:

yarn add gatsby-cli
yarn add detect-port
npx gatsby help

or install detect-port globally:

yarn global add gatsby-cli
yarn global add detect-port
gatsby help

Yep this solves the issue for me. Thanks mate

@DrJulik
Copy link

DrJulik commented May 22, 2020

yarn global add gatsby-cli
yarn global add detect-port
gatsby help

Did it for me. Thanks

@ansonlowzf
Copy link

I tried uninstall gatsby-cli globally and re-install version 2.20.29. The problem persisted.
Will wait the team to update

@PerryMoen
Copy link

Same here. One quick fix is to install everything locally:

yarn add gatsby-cli
yarn add detect-port
npx gatsby help

or install detect-port globally:

yarn global add gatsby-cli
yarn global add detect-port
gatsby help

Thank you!!

n8tg added a commit to n8tg/gatsby-cli-github-action that referenced this issue May 22, 2020
Should resolve build bug #24325 in gatsby-cli gatsbyjs/gatsby#24325
n8tg added a commit to n8tg/Personal-Website that referenced this issue May 22, 2020
@romulociro
Copy link

for me solved using npm
npm i -g gatsby-cli
npm i -g detect-port
gatsby help

@voyager1302
Copy link

for me not solved with yarn or npm
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/gatsby-cli/lib/recipes.js',
'/usr/local/lib/node_modules/gatsby-cli/lib/create-cli.js',
'/usr/local/lib/node_modules/gatsby-cli/lib/index.js'
]

@spartan-dev
Copy link

thanks for all the solutions !! 🚀

@danielricecodes
Copy link

None of the above solutions worked on my Mac. I just downgraded and I will wait for a new version before upgrading gatsby-cli again.

npm i -g gatsby-cli@2.11.2

Problem solved!

@CSIDPsetup
Copy link

For me solved , try this:

- npm install -g gatsby-cli
- npm install -g detect-port

@Awais512
Copy link

for me solved using npm
npm i -g gatsby-cli
npm i -g detect-port
gatsby help

This worked thanks

@freiksenet
Copy link
Contributor

Sorry about that! Fixed in #24334 and released as gatsby-cli@2.12.33

@sohailmahmud
Copy link

for me solved. try this:

npm i -g gatsby-cli
npm i -g detect-port
gatsby help

Thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests