【问题标题】:Can't npm install on Apple Silicon M1无法在 Apple Silicon M1 上安装 npm
【发布时间】:2022-01-22 10:57:03
【问题描述】:

我正在尝试在 M1 Mac 上运行最近克隆的 Gatsby 项目,但它失败了。收到以下错误:

npm ERR! ERR! sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8

我试过brew install vips,然后是npm install 作为解决方案,但没有奏效。真的需要着手处理这个项目。

错误日志如下:

npm ERR! code 1
npm ERR! path /Users/user/Desktop/dev/cassabella/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! CC(target) Release/obj.target/nothing/../node-taddon-api/nothing.o
npm ERR!   LIBTOOL-STATIC Release/nothing.a
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.10.5/libvips-8.10.5-darwin-arm64v8.tar.br
npm ERR! ERR! sharp Prebuilt libvips 8.10.5 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/install for required dependencies
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.13.0 | darwin | arm64
npm ERR! (node:85286) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /usr/bin/python2
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/user/Desktop/dev/cassabella/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/user/Desktop/dev/cassabella/node_modules/sharp/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/user/Desktop/dev/cassabella/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/user/.node-gyp/16.13.0/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/user/.node-gyp/16.13.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/user/Desktop/dev/cassabella/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/user/.node-gyp/16.13.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/user/Desktop/dev/cassabella/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! warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
npm ERR! ../src/common.cc:24:10: fatal error: 'vips/vips8' file not found
npm ERR! #include <vips/vips8>
npm ERR!          ^~~~~~~~~~~~
npm ERR! 1 error 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 (/Users/user/Desktop/dev/cassabella/node_modules/node-gyp/lib/build.js:262:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Darwin 20.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/user/Desktop/dev/cassabella/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/user/Desktop/dev/cassabella/node_modules/sharp
npm ERR! gyp ERR! node -v v16.13.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2021-12-20T21_23_06_624Z-debug.log

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: node.js npm npm-scripts sharp


【解决方案1】:

我刚刚在我的 M1 MacBook Air 上尝试了 npm -g i sharp 并且它工作正常,所以..关于您的机器环境有一些事情需要了解。

  1. brew 公式实际上称为libvips。我没有安装它,npm i sharp 没有它也能正常工作。

  2. 详细查看https://sharp.pixelplumbing.com/install#custom-libvips 和下一节“从源代码构建”。如果您安装了 libvips,您可能需要设置环境变量 SHARP_IGNORE_GLOBAL_LIBVIPS 以忽略它。

  3. 如果可能,请确保 package.json 中的其他 npm 依赖项是最新的。

  4. 作为一种解决方法,您可以创建终端或 iTerm2 的 i386 架构副本,将其放在名为“iTerm2 Rosetta”的应用程序文件夹中,或类似的文件夹中,然后使用文件上的“获取信息”对话框启用 Rosetta。你甚至可以为它设置一个自定义图标。

【讨论】:

  • 非常感谢您的帮助!原来解决方案是运行 yarn install,而不是 npm install。
猜你喜欢
  • 2021-05-08
  • 2021-04-21
  • 2022-01-06
  • 1970-01-01
  • 2021-03-02
  • 2021-03-11
  • 1970-01-01
  • 2022-08-04
相关资源
最近更新 更多