在Apple M1(Big Sur)上使用node-gyp安装本机Node.js附加组件时出错。

7
我正在使用 yarn 安装包,其中包括依赖于 metrohash asset-hash

我不断遇到以下错误:

yarn install v1.22.10
[1/4]   Resolving packages...
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
[4/4]   Building fresh packages...
[-/11] ⠠ waiting...
[10/11] ⠠ metrohash
error /Users/johndoe/Projects/my-project/node_modules/metrohash: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/johndoe/Projects/my-project/node_modules/metrohash
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@15.10.0 | darwin | arm64
gyp info spawn /usr/bin/python2
gyp info spawn args [
gyp info spawn args   '/Users/johndoe/Projects/my-project/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/johndoe/Projects/my-project/node_modules/metrohash/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/johndoe/Projects/my-project/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/johndoe/.node-gyp/15.10.0/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/johndoe/.node-gyp/15.10.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/johndoe/Projects/my-project/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/johndoe/.node-gyp/15.10.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/johndoe/Projects/my-project/node_modules/metrohash',
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=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
clang: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
  CXX(target) Release/obj.target/metrohash/src/metrohash_wrapper.o
  CXX(target) Release/obj.target/metrohash/src/metrohash128.o
clang: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
  CXX(target) Release/obj.target/metrohash/src/metrohash128crc.o
clang: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
In file included from ../src/metrohash128crc.cpp:27:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/nmmintrin.h:15:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/smmintrin.h:13:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/tmmintrin.h:13:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/pmmintrin.h:13:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/emmintrin.h:13:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/xmmintrin.h:13:
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:33:5: error: use of undeclared identifier '__builtin_ia32_emms'; did you mean '__builtin_isless'?
    __builtin_ia32_emms();
    ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:33:5: note: '__builtin_isless' declared here
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:33:25: error: too few arguments to function call, expected 2, have 0
    __builtin_ia32_emms();
                        ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:50:19: error: use of undeclared identifier '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:67:12: error: use of undeclared identifier '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:129:19: error: use of undeclared identifier '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:159:19: error: use of undeclared identifier '__builtin_ia32_packssdw'
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:189:19: error: use of undeclared identifier '__builtin_ia32_packuswb'
    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:216:19: error: use of undeclared identifier '__builtin_ia32_punpckhbw'
    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:239:19: error: use of undeclared identifier '__builtin_ia32_punpckhwd'
    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:260:19: error: use of undeclared identifier '__builtin_ia32_punpckhdq'
    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:287:19: error: use of undeclared identifier '__builtin_ia32_punpcklbw'
    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:310:19: error: use of undeclared identifier '__builtin_ia32_punpcklwd'
    return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:331:19: error: use of undeclared identifier '__builtin_ia32_punpckldq'
    return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: use of undeclared identifier '__builtin_ia32_paddb'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: first argument of MTE builtin function must be a pointer ('__v8qi' (vector of 8 'char' values) invalid)
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^                    ~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: use of undeclared identifier '__builtin_ia32_paddw'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: first argument of MTE builtin function must be a pointer ('__v4hi' (vector of 4 'short' values) invalid)
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^                    ~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:394:19: error: use of undeclared identifier '__builtin_ia32_paddd'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:394:19: error: first argument of MTE builtin function must be a pointer ('__v2si' (vector of 2 'int' values) invalid)
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^                    ~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/metrohash/src/metrohash128crc.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/johndoe/Projects/my-project/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:378:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 20.3.0
gyp ERR! command "/Users/johndoe/.nvm/versions/node/v15.10.0/bin/node" "/Users/johndoe/Projects/my-project/node_modules/metrohash/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/johndoe/Projects/my-project/node_modules/metrohash

我正在使用:
  • MacBook Pro,Apple M1芯片
  • macOS Big Sur 11.2.2操作系统
  • node 15.10.0
  • yarn 1.22.10
我已经尝试过:
  • 尝试使用其他版本的Node(12和14)
  • 运行了xcode-select --install,卸载并重新安装了工具
  • 运行了brew updatebrew upgrade
  • 使用Rosetta模式执行终端
我认为错误可能与Apple M1芯片或最新的Big Sur更新有关。
非常感谢你的帮助。

看起来像是M1问题。你有问过软件包维护者吗? - Joe
不,我没有。Metrohash包已经有两年没有更新了。我的同事说他可以构建它,而且他也在使用M1芯片。不过他使用的是Big Sur 11.0.1版本。 - Axel Meier
4个回答

5
请比较 node-sass 版本和您的 node 版本。
请参考以下截图: enter image description here

不确定为什么在这里提到了 node-sass - highjump

4

在同事的帮助下,我成功解决了错误。

我不得不卸载brew并使用Rosetta重新安装它。然后,我还使用Rosetta模式下的终端重新安装了node和yarn。


9
这只是一种模拟在x86_64中的所有内容的临时方案。 - jdloft

2

我在使用 M1 PromacOS 12.5 Monterey 上遇到了相同的错误。这是我的解决方案:

  1. 删除 node_modules 文件夹
  2. package.json 文件中删除 node-sass
  3. 运行 yarn install
  4. 运行 yarn add node-sass

1
我在macOS 12.1 Monterey上遇到了相同的问题,原因是node-sass-chokidar。当我从旧版NodeJS切换到版本16 LTS时出现了这个问题。
为解决该问题,我做了以下几步:
1. 从package.json中删除node-sass-chokidar 2. 删除node_modules 3. 运行yarn install 4. 使用yarn add node-sass添加node-sass
我还需要更改package.json中“scripts”部分的以下行:
从: "build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/", "watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
到: "build-css": "node-sass --include-path ./src --include-path ./node_modules src/ -o src/", "watch-css": "npm run build-css && node-sass --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
之后一切都正常运行了。
有人谈论使用node-sass而不是node-sass-chokidar的效率(https://pretagteam.com/question/remove-nodesass-from-my-react-project-which-uses-createreactapp),但对我的设置似乎没有影响。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接