全新安装 gatsby 失败,找不到模块 'detect-port'

Fresh install of gatsby fails with cannot find module 'detect-port'

所以我要做的就是安装 gatsby(第一次在我的系统上)。

我的操作系统是:macOS 10.13.6

我的第一步是确保我拥有正确版本的节点/npm:

nvm install 10
npm -v
 6.14.4
node -v
 v10.20.1

然后我简单地尝试安装 gatsby cli:

npm install -g gatsby-cli
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
/Users/me/.nvm/versions/node/v10.20.1/bin/gatsby -> /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/lib/index.js

> core-js@2.6.11 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> gatsby-telemetry@1.3.8 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry
> node src/postinstall.js || true


> gatsby-cli@2.12.31 postinstall /Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli
> node scripts/postinstall.js

npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.

+ gatsby-cli@2.12.31
added 670 packages from 470 contributors in 26.613s

好像完成了?最后我尝试了 运行 东西:

gatsby --help

/Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

Error: Cannot find module 'detect-port'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/Users/me/.nvm/versions/node/v10.20.1/lib/node_modules/gatsby-cli/lib/recipes.js:18:42)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

也许我的设置有问题?谢谢

这是当前 gitub 问题的link:https://github.com/gatsbyjs/gatsby/issues/24325

安装 yarn 和 运行 yarn buildyarn develop 是目前的解决方法。