Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby new fails to install the sharp package and breaks

I can't initiate a gatsby starter project. The new command process breaks down during initialization, and results in an error and non-compilable project.

Here's the command:

> gatsby new gatsby-test

The follwing process starts, failing when during npm install when the sharp package is attempting to install.

info Creating new site from git:
Cloning into 'gatsby-test'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 2309 (delta 4), reused 10 (delta 4), pack-reused 2299
Receiving objects: 100% (2309/2309), 12.62 MiB | 7.98 MiB/s, done.
Resolving deltas: 100% (1487/1487), done.
success Created starter directory layout
info Installing packages...

> [email protected] install /home/developer/projects/gatsby-test/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz
fs.js:114
    throw err;
    ^

Error: EACCES: permission denied, copyfile '/tmp/1890-libvips-8.8.1-linux-x64.tar.gz' -> '/home/developer/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz'
    at Object.copyFileSync (fs.js:1728:3)
    at WriteStream.<anonymous> (/home/developer/projects/gatsby-test/node_modules/sharp/install/libvips.js:104:16)
    at WriteStream.emit (events.js:198:13)
    at lazyFs.close (internal/fs/streams.js:207:14)
    at FSReqWrap.args [as oncomplete] (fs.js:140:20)
make: Entering directory '/home/developer/projects/gatsby-test/node_modules/sharp/build'
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
In file included from ../src/common.cc:25:0:
/usr/include/vips/vips8:35:10: fatal error: glib-object.h: No such file or directory
 #include <glib-object.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
sharp.target.mk:129: recipe for target 'Release/obj.target/sharp/src/common.o' failed
make: *** [Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/home/developer/projects/gatsby-test/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.15.0-70-generic
gyp ERR! command "/usr/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/developer/projects/gatsby-test/node_modules/sharp
gyp ERR! node -v v10.17.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] 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 [email protected] 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!     /home/developer/.npm/_logs/2019-11-18T16_45_16_026Z-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

  - next_tick.js:68 process._tickCallback
    internal/process/next_tick.js:68:7

Any idea what's going on here? I saw there were some problems with sharp in the past but that is supposed to be a closed and fixed issue now. What am I missing here?

like image 286
aviya.developer Avatar asked Nov 18 '19 16:11

aviya.developer


People also ask

Why is Gatsby’s image processing broken up into different packages?

neither any source plugins you are using nor your own implementation of the sourceNodes API are misconfigured Gatsby’s image processing is broken up into different packages which need to work together to source images and transform them into different optimized versions. You might run into these errors getting them to play together nicely.

Why won't my sharp module launch my local Gatsby server?

If you get the following or a similar sharp module related error when trying to launch your local Gatsby server: error Something went wrong installing the "sharp" module The module '/node_modules/sharp/build/Release/sharp.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72.

Can I use Gatsby with a different version of node?

Good to know: if you decide to install another version of Node using NVM, to run your Gatsby project, then you probably have to delete your node_modules directory and run yarn or npm install before trying to run your local Gatsby server again with the downgraded Node.js version.

Why am I getting so many errors in Gatsby develop?

Many errors you encounter will mean adjusting how you’ve configured a plugin or API in your site. This guide is meant as a reference for common errors that have tripped up other Gatsby users. Running a site in gatsby develop will set up a server locally that enables features like hot-module replacement.


Video Answer


4 Answers

You can fix this by running the below in your terminal...

rm -rf /Users/{username}/.npm/_libvips

brew install vips 

rm -rf node_modules

npm install
like image 138
Shodipo Ayomide Avatar answered Oct 17 '22 20:10

Shodipo Ayomide


The following line:

Error: EACCES: permission denied, copyfile '/tmp/1890-libvips-8.8.1-linux-x64.tar.gz' -> '/home/developer/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz'

suggests you have a permissions error moving tmp file to your users local .npm directory. Hard to tell why this is without knowing more context about which user ran the command, etc.


The following line:

fatal error: glib-object.h: No such file or directory

suggests you don't have sharp or vips correctly installed.

npm install sharp

For Ubuntu:

sudo apt-get install -y libvips-tools

For mac:

brew update vips

For archlinux/manjaro:

sudo pacman -S libvips
like image 37
Nick Bull Avatar answered Oct 17 '22 22:10

Nick Bull


I had the same issue. I solved it by downloading the package manually and pasting in

  1. download the libvips from https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz

  2. copy the lib into .npm folder

sudo cp libvips-8.8.1-linux-x64.tar.gz /home/[YOURNAME]/.npm/_libvips/

  1. remove your broken gatsby-test folder

  2. run

gatsby new gatsby-test

again

like image 1
Wai Min Avatar answered Oct 17 '22 21:10

Wai Min


To fix this, I ran:

  • rm -rf node_modules
  • yarn cache clean
  • yarn add --dev yarn-upgrade-all
  • npx yarn-upgrade-all

Then, I re-installed all necessary packages removed from package.json when I ran the command to upgrade all packages. Afterwards, I ran gatsby build and gatsby develop

like image 1
Chiamaka Ikeanyi Avatar answered Oct 17 '22 22:10

Chiamaka Ikeanyi