7

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...

> sharp@0.23.2 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: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.2 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.2 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?

aviya.developer
  • 3,343
  • 2
  • 15
  • 41
  • The gatsby project maintainers recommend `yarn` for building the project. `npm` regularly causes these unexplainable build bugs. I know you should have the choice of package manager. From my experience, since I've used yarn I did not encounter these bugs anymore. – EliteRaceElephant Nov 18 '19 at 21:06
  • 1
    @EliteRaceElephant But all the documentation tutorials and examples are done with npm, is the yarn and official recommendation? – aviya.developer Nov 21 '19 at 10:29
  • I also solved this by switching from npm to yarn. – Juliet Rubin Feb 03 '20 at 05:52

5 Answers5

5

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
Shodipo Ayomide
  • 1,329
  • 13
  • 20
3

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
aloisdg
  • 22,270
  • 6
  • 85
  • 105
Nick Bull
  • 9,518
  • 6
  • 36
  • 58
  • I have it installed, running `sudo apt-get install -y libvips-tools` confirms it. The problem persists. ` – aviya.developer Nov 28 '19 at 11:04
  • How about `sharp`? Test with `npm view sharp version` – Nick Bull Nov 28 '19 at 11:05
  • But should `sharp` be globally installed? `gatsby new ` expects the directory to not exist. How can i install any npm module to it? – aviya.developer Nov 28 '19 at 11:07
  • Also, try `sudo gatsby new gatsby-test`, and see what happens. If this runs without errors, it looks to be a permissions error, and if that is the case I'd hazard a guess it's because of installing gatsby using `sudo` (e.g., `sudo npm i -g gatsby`) – Nick Bull Nov 28 '19 at 11:08
  • `npm view sharp version` outputs: `0.23..3` – aviya.developer Nov 28 '19 at 11:08
  • @aviya.developer Then you're probably okay re `sharp` dependency. I'd personally check next if it could be permissions – Nick Bull Nov 28 '19 at 11:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203235/discussion-between-nick-bull-and-aviya-developer). – Nick Bull Nov 28 '19 at 11:09
  • I installed gatsby with `sudo` and also tried running the command with `sudo`, the output of the question is the result of `sudo gatsby new ` – aviya.developer Nov 28 '19 at 11:09
  • Maybe global npm permissions error. Try the following: `mkdir ~/.npm-global; npm config set prefix '~/.npm-global`. Then add the following line to `~/.profile`: `export PATH=~/.npm-global/bin:$PATH`. Now run `. ~/.profile`, and try to re-install gatsby globally (`npm i -g gatsby`) – Nick Bull Nov 28 '19 at 11:13
1

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

Wai Min
  • 11
  • 2
1

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

0

Try the sudo command. If you're happy with applying root perms to the install.

ackroyd
  • 434
  • 6
  • 6