首页 > 解决方案 > 无法运行 gatsby develop - 加载本地开发命令时出现问题

问题描述

我正在尝试运行 gatsby develop 以启动开发服务器,但出现以下错误:

There was a problem loading the local develop command. Gatsby may not be installed in your site's "node_modules" directory. Perhaps you need to run "npm install"? You might need to delete your "package-lock.json" as well.

这是我正在从事的项目:https ://github.com/andreiprv/andyprv-blog

从此仓库克隆:https ://github.com/alxshelepenok/gatsby-starter-lumen

这可能是一个依赖问题,但我不知道如何解决它。在我使用 gatsby new 等启动项目后,出现以下错误:

    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE unable to resolve dependency tree
    npm ERR!
    npm ERR! While resolving: gatsby-starter-lumen@3.0.7
    npm ERR! Found: react@17.0.1
    npm ERR! node_modules/react
    npm ERR!   react@"^17.0.1" from the root project
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! peer react@"^16.4.2" from gatsby@2.28.0
    npm ERR! node_modules/gatsby
    npm ERR!   gatsby@"^2.27.4" from the root project
    npm ERR!   peer gatsby@"*" from @sentry/gatsby@5.28.0
    npm ERR!   node_modules/@sentry/gatsby
    npm ERR!     @sentry/gatsby@"^5.27.6" from the root project
    npm ERR!
    npm ERR! Fix the upstream dependency conflict, or retry
    npm ERR! this command with --force, or --legacy-peer-deps
    npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
    npm ERR!
    npm ERR! See /Users/andreismbp/.npm/eresolve-report.txt for a full report.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/andreismbp/.npm/_logs/2020-12-04T17_22_00_512Z-debug.log
    error Command failed with exit code 1: npm install
    
    
      Error: Command failed with exit code 1: npm install
    
      - error.js:56 makeError
        [lib]/[gatsby-cli]/[execa]/lib/error.js:56:11
    
      - index.js:114 handlePromise
        [lib]/[gatsby-cli]/[execa]/index.js:114:26
    
      - task_queues:93 processTicksAndRejections
        node:internal/process/task_queues:93:5
    
      - init-starter.js:135 install
        [lib]/[gatsby-cli]/lib/init-starter.js:135:7
    
      - init-starter.js:202 clone
        [lib]/[gatsby-cli]/lib/init-starter.js:202:3
    
      - init-starter.js:343 initStarter
        [lib]/[gatsby-cli]/lib/init-starter.js:343:5
    
      - create-cli.js:449
        [lib]/[gatsby-cli]/lib/create-cli.js:449:9

我尝试再次使用卸载并安装 gatsbynpm uninstall --save gatsby && npm install --save gatsby

但它失败并出现以下错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: gatsby-starter-lumen@3.0.7
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.4.2" from gatsby@2.28.0
npm ERR! node_modules/gatsby
npm ERR!   peer gatsby@"*" from @sentry/gatsby@5.28.0
npm ERR!   node_modules/@sentry/gatsby
npm ERR!     @sentry/gatsby@"^5.27.6" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/andreismbp/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/andreismbp/.npm/_logs/2020-12-04T17_51_08_843Z-debug.log

先感谢您!

标签: reactjsgatsby

解决方案


做了以下,跑npm install --legacy-peer-deps

然后在运行时遇到另一个错误gatsby develop

Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (88)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
error undefined failed

通过将节点降级到 v14.15.1 来修复上述问题。之后我需要跑步npm rebuild node-sass


推荐阅读