gyp error when I want to do React native npm install

Viewed 488

When I want to npm install in a React native project, I get the following error. When I researched the problem on the internet, I tried to downgrade the node versions. I am currently using v16.14.2 as the node version. I also tried to install with yarn instead of npm but that seems like the wrong method. I couldn't find much solution. Can anyone help?

npm ERR! code 1
npm ERR! path /Users/baturalposma/Desktop/Masaüstü/MobileApps/Milan/node_modules/sharp
npm ERR! command failed
npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
npm ERR! TOUCH Release/obj.target/libvips-cpp.stamp
npm ERR!   CXX(target) Release/obj.target/sharp/src/common.o
npm ERR! info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-darwin-arm64v8.tar.gz
npm ERR! ERR! sharp Prebuilt libvips binaries are not yet available for darwin-arm64v8
npm ERR! info sharp Attempting to build from source via node-gyp but this may fail due to the above error
npm ERR! info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@16.14.2 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.8.9 found at "/Applications/Xcode.app/Contents/Developer/usr/bin/python3"
npm ERR! gyp info spawn /Applications/Xcode.app/Contents/Developer/usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/opt/homebrew/Cellar/node@16/16.14.2/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/baturalposma/Desktop/Masaüstü/MobileApps/Milan/node_modules/sharp/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/opt/homebrew/Cellar/node@16/16.14.2/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/baturalposma/Library/Caches/node-gyp/16.14.2/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/baturalposma/Library/Caches/node-gyp/16.14.2',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/Cellar/node@16/16.14.2/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/baturalposma/Library/Caches/node-gyp/16.14.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/baturalposma/Desktop/Masaüstü/MobileApps/Milan/node_modules/sharp',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/common.cc:22:
npm ERR! In file included from /Users/baturalposma/Library/Caches/node-gyp/16.14.2/include/node/node.h:63:
npm ERR! In file included from /Users/baturalposma/Library/Caches/node-gyp/16.14.2/include/node/v8.h:30:
npm ERR! /Users/baturalposma/Library/Caches/node-gyp/16.14.2/include/node/v8-internal.h:492:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
npm ERR!             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                 ~~~~~^~~~~~~~~~~
npm ERR!                                      remove_cv
npm ERR! /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:715:50: note: 'remove_cv' declared here
npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
npm ERR!                                                  ^
npm ERR! ../src/common.cc:25:10: fatal error: 'vips/vips8' file not found
npm ERR! #include <vips/vips8>
npm ERR!          ^~~~~~~~~~~~
npm ERR! 2 errors generated.
npm ERR! make: *** [Release/obj.target/sharp/src/common.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/opt/homebrew/Cellar/node@16/16.14.2/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:526:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 21.4.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node@16/16.14.2/bin/node" "/opt/homebrew/Cellar/node@16/16.14.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/baturalposma/Desktop/Masaüstü/MobileApps/Milan/node_modules/sharp
npm ERR! gyp ERR! node -v v16.14.2
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/baturalposma/.npm/_logs/2022-04-25T12_01_10_953Z-debug-0.log
1 Answers

If you are on an M1 MacBook or any Apple Silicon chip Macbook the default python installation is Python 3.8.9 or higher this might cause issues during compilation and linking of certain libraries like node-sass. To resolve this issue you have two options:

  • Find a replacement for the library that is causing npm errors. In the case of node-sass, you can install npm install sass.
  • If there are no replacements for your library then you have to install python 2 on your system. Follow steps 1 - 6
  1. $ brew install pyenv
  2. $ pyenv install 2.7.18
  3. Set the following environment variables in your .zshrc or .bashrc depending on your default shell.
export PATH=$(pyenv root)/shims:$PATH
export PATH="$(pyenv root)/versions/2.7.18/bin:$PATH"
  1. $ source ~/.zshrc or ~/.bashrc depending on your default shell.
  2. npm config set python python2.7
  3. $ rm -rf node_module && npm i

Copy the commands after $ and execute them on your terminal.

Related