【问题标题】:Error when trying to install Sharp for Gatsby尝试为 Gatsby 安装 Sharp 时出错
【发布时间】:2019-05-27 06:55:51
【问题描述】:

我刚开始使用 Gatsby。我可以使用 Gatsby 的默认启动器,但任何其他启动器似乎都依赖于 Sharp,无论我做什么,安装都会失败。

    info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.6.1/libvips-8.6.1-darwin-x64.tar.gz
/Users/djfriar/Sites/gatsby-pretty/node_modules/sharp/install/libvips.js:76
          throw err;
          ^

Error: self signed certificate in certificate chain
    at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34)
    at TLSSocket.emit (events.js:182:13)
    at TLSSocket._finishInit (_tls_wrap.js:631:8)
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34)
gyp ERR! stack     at TLSSocket.emit (events.js:182:13)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:631:8)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/djfriar/Sites/gatsby-pretty/node_modules/sharp
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.20.8 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.20.8 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/djfriar/.npm/_logs/2018-12-30T06_05_17_559Z-debug.log
error Command failed: npm install

有人知道我在这里可能缺少什么吗?

【问题讨论】:

  • 仅供参考我在安装sharp时无法复制这个,所以你的本地配置肯定有问题。 :/ 查看herehere 以获得可能的解决方案。
  • 你需要安装node-gyp:github.com/nodejs/node-gyp#installation
  • 我确实安装了 node-gyp。版本 2.7.10
  • 在安装额外的依赖项之前,请确保问题不是由过时的锁定文件引起的。删除您的package-lock.jsonyarn.lock,您的node_modules 目录,然后重试

标签: gatsby sharp


【解决方案1】:

尝试删除您的 node_modulespackage-lock.json(如果使用 npm)或 yarn.lock(如果使用 yarn)。

使用 npm

$ rm -rf node_modules package-lock.json
$ npm install
$ npm run build

用纱

$ rm -rf node_modules yarn.lock
$ yarn
$ yarn build

这为我解决了这个问题。我的yarn.lock 似乎与我的 Node 版本冲突并导致错误。

如果这对您不起作用,请查看 this GitHub issuethis one,其中提到了其他可能的修复方法。

【讨论】:

    【解决方案2】:

    尽可能避免将sudonpm install 一起使用。如果您绝对必须使用 sudo,请添加 npm install --unsafe-perm 标志。

    【讨论】:

      【解决方案3】:

      我将json包中的“sharp”:“^0.21”,改为“sharp”:“^0.22.1”,终于成功了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-21
        • 1970-01-01
        • 1970-01-01
        • 2011-12-04
        • 2017-09-15
        • 2017-10-11
        • 2015-01-17
        • 2013-11-13
        相关资源
        最近更新 更多