【问题标题】:Unable to run Gatsby project无法运行 Gatsby 项目
【发布时间】:2022-01-19 02:03:32
【问题描述】:

当我运行 Gatsby v2.19.19 时出现以下错误

Gatsby requires Node.js 14.15.0 or higher (you have v12.13.0)

问题是,如果我切换到高于 14.15.0 的版本,那么无论我做什么,我的一些依赖项都不会安装。例如,gatsby-plugin-favicon gatsby-transformer-sharp gatsby-plugin-sharp 都依赖于名为 sharp 的包

我也无法使用 node v12 安装依赖项,然后切换到 v14 并运行相同包的项目原因(文档明确声明它必须在相同版本的 node 上安装和运行)

此外,在 Gatsby v2 -> v3 迁移指南中,它说 v3 所需的最低节点版本是 12.13.0。鉴于我使用的是 v2,它甚至应该低于这个值,因此我不明白说我必须拥有 14.15.0 或更高版本的错误。

这是我的package.json 文件

  "scripts": {
    "develop": "gatsby develop",
    "build:develop": "OSS_ENV=staging gatsby build",
    "build": "OSS_ENV=production gatsby build",
    "serve": "gatsby serve"
  },
  "dependencies": {
    "@stripe/stripe-js": "^1.13.1",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "email-validator": "^2.0.4",
    "express": "^4.17.1",
    "gatsby-plugin-google-tagmanager": "^2.1.25",
    "gatsby-plugin-robots-txt": "^1.5.0",
    "gatsby-plugin-sitemap": "^2.2.27",
    "pngquant-bin": "^6.0.0",
    "superagent": "^6.1.0"
  },
  "devDependencies": {
    "antd": "^3.26.11",
    "axios": "^0.21.1",
    "gatsby": "^2.19.18",
    "gatsby-image": "^2.2.41",
    "gatsby-plugin-antd-v2": "^1.0.3",
    "gatsby-plugin-favicon": "^3.1.6",
    "gatsby-plugin-less": "^4.7.0",
    "gatsby-plugin-react-helmet": "^3.1.22",
    "gatsby-plugin-sass": "^3.2.0",
    "gatsby-plugin-sharp": "^2.4.5",
    "gatsby-plugin-typescript": "^2.1.27",
    "gatsby-source-filesystem": "^2.1.48",
    "gatsby-source-ghost": "^4.2.2",
    "gatsby-transformer-sharp": "^2.3.14",
    "less": "^4.1.1",
    "node-sass": "^5.0.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "react-icons": "^4.2.0"
  }

在节点 v14.15.0 或更高版本上安装我上面提到的软件包时遇到的错误

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.4 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sharp@0.23.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

【问题讨论】:

  • “不会安装”是什么意思?他们是否显示错误?
  • Node 版本升级到 14 时,是否删除了 package-lock.jsonnode_modules
  • @FerranBuireu 是的,我有
  • @evolutionxbox 我用错误更新了我的问题
  • 听起来sharp需要更新?

标签: javascript reactjs gatsby gatsby-plugin


【解决方案1】:

您是否尝试过使用 libvips 依赖项?

根据某些GitHub threads 的说法,问题似乎libvipssharp 的依赖项,gatsby-plugin-sharp 使用它(存在于您的package.json 中)。只是为了确认这个插件是您问题的原因,请尝试删除它并重新安装模块。

要绕过这个问题,您可以手动尝试installing libvips

rm -rf /Users/{username}/.npm/_libvips
brew install vips 
rm -rf node_modules
npm install

当然,这是假设 MacOS 系统。

其他线程建议从 npm 切换到 yarn。

相关问题:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    相关资源
    最近更新 更多