Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail to install gatsby starter because of sharp

Tags:

gatsby

sharp

I got these error in terminal when I want to install a gatsby starter. Anyone get any idea how to solve it?

[4/4] 🔨  Building fresh packages...
[6/13] ⠁ sharp
[-/13] ⠁ waiting...
[-/13] ⠁ waiting...
[12/13] ⠁ sharp
error /Users/anykey/Documents/GitHub/a1000/node_modules/favicons/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /Users/anykey/Documents/GitHub/a1000/node_modules/favicons/node_modules/sharp
Output:
info sharp Detected globally-installed libvips v8.8.3
info sharp Building from source via node-gyp
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info find Python using Python version 2.7.10 found at "/usr/bin/python"
gyp info spawn /usr/bin/python
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/anykey/Documents/GitHub/a1000/node_modules/favicons/node_modules/sharp/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/anykey/Library/Caches/node-gyp/10.16.3/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/anykey/Library/Caches/node-gyp/10.16.3',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/anykey/Library/Caches/node-gyp/10.16.3/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/anykey/Documents/GitHub/a1000/node_modules/favicons/node_modules/sharp',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
gyp: Call to 'PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:344:16)
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 Darwin 18.5.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/anykey/Documents/GitHub/a1000/node_modules/favicons/node_modules/sharp
gyp ERR! node -v v10.16.3
like image 953
Wing Cheung Kwok Avatar asked Sep 28 '19 18:09

Wing Cheung Kwok


4 Answers

The problem may be due to node v12.x and using npm instead of yarn which caused me issues.

Steps to solve the issue.

1) Downgrade your node version to 10.x (where v10.16.0 solved the problem for me) using nvm(to manage different node versions). commands for nvm are:

 a) "nvm install 10.16.0" (to install node version).

 b) "nvm use 10.16.0" (to switch between different node versions).

2) Use yarn to install the dependencies using command:

  yarn

If already used npm, then remove node_modules and package.lock.json and then try the above steps.

like image 174
Gurjot Singh Avatar answered Nov 13 '22 16:11

Gurjot Singh


I had vips installed with Homebrew. Uninstalling it solved the issue in my case, by running:

brew uninstall vips
and then:
yarn install (or npm install)

like image 2
Oleg Korol Avatar answered Nov 13 '22 16:11

Oleg Korol


I had a similar problem. In my case there was something like below in the error log

error /<path to the project>/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /<path to the project>/node_modules/sharp
Output:
info sharp Using cached /home/username/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz
ERR! sharp Please delete /home/username/.npm/_libvips/libvips-8.8.1-linux-x64.tar.gz as it is not a valid tarball

As you can see in the last lines sharp is using cached version of libvips, deleting cached libvips tarball fixed the issue for me.


But for OP it seems he/she have installed libvips globally according the following line from the error log

info sharp Detected globally-installed libvips v8.8.3
npm -g uninstall libvips

will probably fix his/her issue.

like image 1
user158 Avatar answered Nov 13 '22 17:11

user158


As I had several node version installed downgrading to previous one works for me

First I checked for available and in use node version

nvm ls
         v12.18.4
  ->     v14.15.0
         v14.15.1

Then downgraded to the previous node version

nvm use v12.18.4

So yarn installation in my Gatsby product folder works fine again

cd my-gatsby-folder
yarn install

You could decide to use old node version as default

nvm alias default 12
like image 1
Robbo Avatar answered Nov 13 '22 17:11

Robbo