gatsby: Error thrown when using the Gatsby CLI after install - "Error: Cannot find module 'detect-port'"
Description
When I installed the gatsby CLI, I was unable to run it; it throws this exception in the command line:
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
- Install
gatsby-cli
globally. - 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) - 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® Core™ 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 16 (2 by maintainers)
Commits related to this issue
- Add detect-port to install Should resolve build bug #24325 in gatsby-cli https://github.com/gatsbyjs/gatsby/issues/24325 — committed to n8tg/gatsby-cli-github-action by n8tg 4 years ago
- Should resolve build bug #24325 in gatsby-cli https://github.com/gatsbyjs/gatsby/issues/24325 — committed to n8tg/Personal-Website by n8tg 4 years ago
This exact same thing happened to me as well.
Same here. One quick fix is to install everything locally:
or install
detect-port
globally: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!
Sorry about that! Fixed in #24334 and released as
gatsby-cli@2.12.33
for me solved using npm npm i -g gatsby-cli npm i -g detect-port gatsby help
Yep this solves the issue for me. Thanks mate
This is currently happening in my builds as well; using the
gatsby-cli
installed locally in my project’snode_modules
(by usingyarn build
instead ofgatsby build
, in my case) instead of the global install appears to be a workaround becausedetect-port
is already installed (as a way to avoid globally installingdetect-port
).