简体   繁体   English

无法运行 Gatsby 项目

[英]Unable to run Gatsby project

When I run Gatsby v2.19.19 I get the following error当我运行 Gatsby v2.19.19 时出现以下错误

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

The problem is if that I switch to anything higher than 14.15.0 some of my dependecies won't install no matter what I do.问题是如果我切换到高于 14.15.0 的任何版本,无论我做什么,我的一些依赖项都不会安装。 For instance, gatsby-plugin-favicon gatsby-transformer-sharp gatsby-plugin-sharp that all depend on the package called sharp例如, gatsby-plugin-favicon gatsby-transformer-sharp gatsby-plugin-sharp都依赖于名为sharp的package

I also can't install the dependecies using node v12 and then switch to v14 and run the project cause of the same package (the docs explicitly state that it has to be installed and run on the same version of node)我也无法使用节点 v12 安装依赖项,然后切换到 v14 并运行相同 package 的项目原因(文档明确 state 必须在相同版本的节点上安装和运行)

Also, in Gatsby v2 -> v3 migration guide it says that minimal required node version for v3 is 12.13.0.此外,在 Gatsby v2 -> v3 迁移指南中,它说 v3 所需的最低节点版本是 12.13.0。 Given that I work with v2 it should even be lower than that, therefore I do not understand the error that says that I have to have 14.15.0 or above.鉴于我使用的是 v2,它甚至应该低于这个值,因此我不明白说我必须拥有 14.15.0 或更高版本的错误。

Here is my package.json file这是我的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"
  }

The error I get while installing the packages I mentioned above on node v14.15.0 or above在节点 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.

Have you tried playing with libvips dependency?您是否尝试过使用libvips依赖项?

According to some GitHub threads , the issue seems that libvips is a dependency for sharp which gatsby-plugin-sharp uses (present in your package.json ).根据一些GitHub 线程,问题似乎libvipsgatsby-plugin-sharp sharp的Sharp的依赖项(存在于您的package.json中) Just to confirm that this plugin is the cause of your issue, try removing it and reinstalling the modules again.只是为了确认此插件是您问题的原因,请尝试将其删除并重新安装模块。

To bypass this issue you can try installing libvips manually:要绕过此问题,您可以尝试手动安装libvips

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

Of course, this assumes a MacOS system.当然,这是假设 MacOS 系统。

Other threads suggest switching from npm to yarn.其他线程建议从 npm 切换到纱线。

Related issues:相关问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM