【问题标题】:gatsby new [site] failing: Cannot find module 'gatsby/dist/commands/develop'gatsby new [site] 失败:找不到模块 'gatsby/dist/commands/develop'
【发布时间】:2018-02-01 18:37:00
【问题描述】:

我在这里很绿。我以前在这个(macosx)上运行过 gatsby。它已停止工作 - 可能是由于某处的安装或环境变量?

首先注意到模块构建失败:错误:找不到相对于目录“/Users/3Legs”的预设“流”

然后在安装 babel 预设后:

npm install --global --save-dev babel-preset-flow

我收到上述消息:

gatsby develop

...找不到模块“gatsby/dist/commands/develop”

下面的完整轨迹 + babelrc

Michaels-MacBook-Air:mggatsby 3Legs$

gatsby new test

-bash: /usr/local/bin/gatsby: 没有那个文件或目录 Michaels-MacBook-Air:mggatsby 3Legs$

npm install --global gatsby-cli

WARN registry Unexpected warning for registry.npmjs.org: Miscellaneous Warning EINTEGRITY: sha1-xRn2KfhrOlvtuliojTETCe7Al/k= integrity checksum failed when using sha1: wanted sha1-xRn2KfhrOlvtuliojTETCe7Al/k= but got sha512-vE2hT1D0HLZCLLclfBSfkfTTedhVj0fubHpJBHKwwUWX0nSbhPAfk+SG9rTX95BYNmau8rGFfCeaT6T5OW1C2A==. (455516 bytes)
WARN registry Using stale package data from registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha1-buxr+wdCHiFIx1xrunJCH4UwqCY= integrity checksum failed when using sha1: wanted sha1-buxr+wdCHiFIx1xrunJCH4UwqCY= but got sha512-+ktMAh1Jwas+TnGodfCfjUbJKoANqPaJFN0z0iqh41eqD8dvguNzcitVSBSVK1pidz0AqGbLKcoVuVLRVZ/aVg==. (42903 bytes)
WARN registry Using stale package data from registry.npmjs.org/ due to a request error during revalidation.
/usr/local/bin/gatsby -> /usr/local/lib/node_modules/gatsby-cli/lib/index.js
+ gatsby-cli@1.1.1
added 153 packages, removed 5 packages and updated 1 package in 10.573s
Michaels-MacBook-Air:mggatsby 3Legs$ 
    gatsby new test
info Creating new site from git: git://github.com/gatsbyjs/gatsby-starter-default.git
Cloning into 'test'...
remote: Counting objects: 566, done.
remote: Total 566 (delta 0), reused 0 (delta 0), pack-reused 566
Receiving objects: 100% (566/566), 358.35 KiB | 187.00 KiB/s, done.
Resolving deltas: 100% (316/316), done.
success Created starter directory layout
info Installing packages...
yarn install v0.27.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "eslint-config-fbjs@1.1.1" has unmet peer dependency "babel-eslint@^6.1.2".
warning "eslint-config-fbjs@1.1.1" has unmet peer dependency "eslint@^3.0.0".
warning "eslint-config-fbjs@1.1.1" has unmet peer dependency "eslint-plugin-babel@^3.3.0".
warning "eslint-config-fbjs@1.1.1" has unmet peer dependency "eslint-plugin-flowtype@^2.15.0".
warning "eslint-config-fbjs@1.1.1" has unmet peer dependency "eslint-plugin-react@^5.2.2".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 47.94s.
Michaels-MacBook-Air:mggatsby 3Legs$ 
    cd test
Michaels-MacBook-Air:test 3Legs$ 
    gatsby develop
success delete html files from previous builds — 0.010 s
success open and validate gatsby-config.js — 0.006 s
success copy gatsby files — 0.028 s
success source and transform nodes — 0.045 s
success building schema — 0.134 s
success createLayouts — 0.039 s
success createPages — 0.016 s
success createPagesStatefully — 0.016 s
success extract queries from components — 0.118 s
success run graphql queries — 0.030 s
success write out page data — 0.006 s
success update schema — 0.094 s

info bootstrap finished - 3.856 s

error There was an error compiling the html.js component for the development server.

See our docs page on debugging HTML builds for help ...

错误:模块构建失败:错误:找不到相对于目录“/Users/3Legs”的预设“流程”

Michaels-MacBook-Air:test 3Legs$ 
    npm install --save-dev babel-preset-flow 
    npm WARN gentlyRm not removing /Users/3Legs/react/mggatsby/test/node_modules/.bin/gatsby as it wasn't installed by /Users/3Legs/react/mggatsby/test/node_modules/gatsby
    npm WARN gentlyRm not removing /Users/3Legs/react/mggatsby/test/node_modules/.bin/semver as it wasn't installed by /Users/3Legs/react/mggatsby/test/node_modules/semver
    npm WARN gentlyRm not removing /Users/3Legs/react/mggatsby/test/node_modules/jspm-registry/node_modules/.bin/semver as it wasn't installed by /Users/3Legs/react/mggatsby/test/node_modules/jspm-registry/node_modules/semver
    npm WARN gentlyRm not removing /Users/3Legs/react/mggatsby/test/node_modules/.bin/browserslist as it wasn't installed by /Users/3Legs/react/mggatsby/test/node_modules/browserslist
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN gatsby-starter-default@1.0.0 No repository field.


+ babel-preset-flow@6.23.0
removed 1375 packages and updated 6 packages in 17.729s
Michaels-MacBook-Air:test 3Legs$ 
    gatsby develop
/usr/local/bin/gatsby develop

Options:
  -h, --help     Show help                                                   [boolean]
  -H, --host     Set host. Defaults to localhost                              [string]
  -p, --port     Set port. Defaults to 8000                 [string] [default: "8000"]
  -o, --open     Open the site in your browser for you.                      [boolean]
  -v, --version  Show version number                                         [boolean]

error There was a problem loading the local develop command. Gatsby may not be installed.

错误:找不到模块“gatsby/dist/commands/develop”

  - index.js:17 resolveFileName
    [lib]/[gatsby-cli]/[resolve-from]/index.js:17:39

  - index.js:31 resolveFrom
    [lib]/[gatsby-cli]/[resolve-from]/index.js:31:9

  - index.js:34 module.exports
    [lib]/[gatsby-cli]/[resolve-from]/index.js:34:41

  - index.js:4 module.exports.moduleId
    [lib]/[gatsby-cli]/[resolve-cwd]/index.js:4:30

  - create-cli.js:35 resolveLocalCommand
    [lib]/[gatsby-cli]/lib/create-cli.js:35:22

  - create-cli.js:66 Object.handler
    [lib]/[gatsby-cli]/lib/create-cli.js:66:7

  - command.js:233 Object.self.runCommand
    [lib]/[gatsby-cli]/[yargs]/lib/command.js:233:22

  - yargs.js:990 Object.Yargs.self._parseArgs
    [lib]/[gatsby-cli]/[yargs]/yargs.js:990:30

  - yargs.js:532 Object.Yargs.self.parse
    [lib]/[gatsby-cli]/[yargs]/yargs.js:532:23

  - create-cli.js:163 module.exports
    [lib]/[gatsby-cli]/lib/create-cli.js:163:154

  - index.js:122 Object.<anonymous>
    [lib]/[gatsby-cli]/lib/index.js:122:1

Michaels-MacBook-Air:~ 3Legs$ 
    cat .babelrc 
{
  "presets": ["flow"]
}

【问题讨论】:

    标签: babeljs flow gatsby


    【解决方案1】:

    NPM 似乎正在删除模块,因为没有 package-lock.json。不确定这是否是新行为,但在过去的几天里已经影响了很多人。

    您需要做的就是删除 node_modules 和那里的所有锁定文件并运行 npm install

    【讨论】:

    • 它仍然不适合我。我尝试了 rm -r node_modules,删除锁定文件,我还尝试了新的 gatsby 目录/构建(gatsby 新测试)。我仍然遇到相同的错误(或者如果我删除 node_modules 并运行 npm install 我得到丢失的文件错误(找不到模块:错误:无法解析 /Users/3Legs/react/sgcopy/node_modules/gatsby/dist/ 中的模块'config'同构)我什至在阅读这是一个问题后尝试了 npm upgrade -g gatsby-cli 但这没有帮助。有什么想法吗?如果我可以运行一个“gatsby 新站点”,那会让我继续前进。
    • 我会安装 Yarn 并尝试使用它。
    • yarn 本身不能工作......但我运行它然后尝试了这个确实有效: cat ~/.babelrc { "presets": ["flow"] } mv ~/.babelrc ~/.babelrcold
    • 我也经常遇到这种情况。无法解释为什么,但我已经能够通过卸载任何软件包然后以不同的顺序再次安装它们来解决这个问题(偶然碰到这个)。尝试了 npm 和 yarn 一样的东西。
    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 2022-01-11
    • 2019-07-03
    • 2020-03-14
    • 1970-01-01
    • 2020-02-06
    • 2019-12-11
    • 2021-03-17
    相关资源
    最近更新 更多