5

I'm new to using Gatsby. I am able to use the default starter for Gatsby, but any other starter seems to rely on Sharp, and the installation of that is failing no matter what I do.

    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

Does anyone know what I may be missing here?

DJFriar
  • 340
  • 7
  • 21
  • FYI I cannot replicate this when installing sharp so it's for sure some issue with your local configuration. :/ Check out [here](https://stackoverflow.com/questions/9626990/receiving-error-error-ssl-error-self-signed-cert-in-chain-while-using-npm) and [here](https://stackoverflow.com/questions/22096459/self-signed-cert-in-chain-error-on-elastic-beanstalk-for-nodejs?noredirect=1&lq=1) for possible solutions. – Morgan Dec 30 '18 at 06:40
  • You need to have node-gyp installed: https://github.com/nodejs/node-gyp#installation – LekoArts Dec 30 '18 at 13:55
  • I do have node-gyp installed. Version 2.7.10 – DJFriar Dec 30 '18 at 17:47
  • Before installing an extra dependency, make sure the issue isn't caused by an outdated lockfile. Delete your `package-lock.json` or `yarn.lock`, your `node_modules` directory and try again – Robin Métral Sep 08 '19 at 16:53

3 Answers3

5

Try deleting your node_modules and your package-lock.json (if using npm) or yarn.lock (if using yarn).

With npm

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

With yarn

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

This fixed the issue for me. It seems that my yarn.lock was conflicting with my Node version and caused the error.

If this doesn't work for you, take a look at this GitHub issue or this one, where other potential fixes are mentioned.

Robin Métral
  • 3,099
  • 3
  • 17
  • 32
0

Avoid using sudo with npm install where possible. If you absolutely have to use sudo then add the npm install --unsafe-perm flag.

Akhil S
  • 955
  • 11
  • 16
-1

I changed "sharp": "^0.21",to "sharp": "^0.22.1" in package json, and finally it worked.

m.eslampnah
  • 169
  • 1
  • 4
  • 10