【问题标题】:gyp error when I want to do React native npm install当我想做 React native npm install 时出现 gyp 错误
【发布时间】:2022-07-26 22:38:00
【问题描述】:

当我想在 React 本机项目中安装 npm 时,我收到以下错误。当我在互联网上研究问题时,我试图降级节点版本。我目前使用 v16.14.2 作为节点版本。我也尝试使用 yarn 而不是 npm 安装,但这似乎是错误的方法。我找不到太多解决方案。有人可以帮忙吗?

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

【问题讨论】:

  • 如错误消息所述,您需要一个较早的节点来获取预构建的二进制文件。也许尝试v15?如果您必须使用 v16,则需要在 M1 上设置自制软件并让外部链接正常工作。

标签: react-native npm


【解决方案1】:

如果您使用的是 M1 MacBook 或任何 Apple Silicon 芯片 Macbook,则默认的 Python 安装是 Python 3.8.9 或更高版本,这可能会在编译和链接某些库(如 node-sass)时出现问题。要解决此问题,您有两种选择:

  • 查找导致 npm 错误的库的替换。在 node-sass的情况下,可以安装npm install sass
  • 如果您的库没有替代品,那么您必须安装 python 2 在您的系统上。按照步骤 1 - 5
  1. $ brew install pyenv
  2. $ pyenv 安装 2.7.18
  3. 根据您的默认 shell,在 .zshrc 或 .bashrc 中设置以下环境变量。
export PATH=$(pyenv root)/shims:$PATH
export PATH="$(pyenv root)/versions/2.7.18/bin:$PATH"
  1. $ source ~/.zshrc 或 ~/.bashrc 取决于您的默认 shell。
  2. $ rm -rf node_module && npm i

复制 $ 之后的命令并在终端上执行。

【讨论】:

    猜你喜欢
    • 2021-08-05
    • 2013-09-17
    • 2018-02-07
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2017-02-02
    相关资源
    最近更新 更多