当前位置:   article > 正文

解决m1芯片Mac安装node失败问题_mac m1安装不了node-pre-gyp

mac m1安装不了node-pre-gyp

用nvm安装node时终端报错: 

  1. .type aesni_cbc_sha256_enc_avx2,@function
  2. ^
  3. ../deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.s:2439:8: error: invalid alignment value
  4. .align 64
  5. ^
  6. ../deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.s:4080:1: error: unknown directive
  7. .size aesni_cbc_sha256_enc_avx2,.-aesni_cbc_sha256_enc_avx2
  8. ^
  9. ../deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.s:4081:1: error: unknown directive
  10. .type aesni_cbc_sha256_enc_shaext,@function
  11. ^
  12. ../deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.s:4082:8: error: invalid alignment value
  13. .align 32
  14. ^
  15. ../deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.s:4435:1: error: unknown directive
  16. .size aesni_cbc_sha256_enc_shaext,.-aesni_cbc_sha256_enc_shaext
  17. ^
  18. make[1]: *** [/Users/admin/.nvm/.cache/src/node-v10.24.1/files/out/Release/obj.target/openssl/deps/openssl/config/archs/linux-x86_64/asm_avx2/crypto/aes/aesni-sha256-x86_64.o] Error 1
  19. rm a151194e89fcf3752f3d05351e9f891bee165204.intermediate
  20. make: *** [node] Error 2
  21. nvm: install v10.24.1 failed!

或者安装npm包时终端报错:

  1. <--- Last few GCs --->
  2. [57807:0x128008000] 54 ms: Scavenge 11.1 (14.0) -> 10.5 (14.8) MB, 0.4 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  3. [57807:0x128008000] 58 ms: Scavenge 11.7 (15.0) -> 11.1 (15.8) MB, 0.3 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  4. [57807:0x128008000] 66 ms: Scavenge 13.4 (16.4) -> 12.8 (21.9) MB, 0.7 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
  5. <--- JS stacktrace --->
  6. FATAL ERROR: wasm code commit Allocation failed - process out of memory
  7. 1: 0x102290c38 node::Abort() [/opt/homebrew/bin/node]
  8. 2: 0x102290db8 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string<std::nullptr_t>(char const*) [/opt/homebrew/bin/node]
  9. 3: 0x102396c14 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/homebrew/bin/node]
  10. 4: 0x102396ba8 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/homebrew/bin/node]
  11. 5: 0x1027c4fa4 v8::internal::wasm::WasmCodeAllocator::AllocateForCodeInRegion(v8::internal::wasm::NativeModule*, unsigned long, v8::base::AddressRegion) [/opt/homebrew/bin/node]
  12. 6: 0x1027c5c1c v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(unsigned int, v8::base::AddressRegion) [/opt/homebrew/bin/node]
  13. 7: 0x1027c51e8 v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion) [/opt/homebrew/bin/node]
  14. 8: 0x1027c5a64 v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, bool, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptr<v8::internal::Counters>, std::__1::shared_ptr<v8::internal::wasm::NativeModule>*) [/opt/homebrew/bin/node]
  15. 9: 0x1027c7944 v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine*, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/opt/homebrew/bin/node]
  16. 10: 0x1027cdc70 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/opt/homebrew/bin/node]
  17. 11: 0x1027cdbb8 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/opt/homebrew/bin/node]
  18. 12: 0x1027ac3a8 v8::internal::wasm::AsyncCompileJob::CreateNativeModule(std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/opt/homebrew/bin/node]
  19. 13: 0x1027b3860 v8::internal::wasm::AsyncCompileJob::PrepareAndStartCompile::RunInForeground(v8::internal::wasm::AsyncCompileJob*) [/opt/homebrew/bin/node]
  20. 14: 0x1027b4004 v8::internal::wasm::AsyncCompileJob::CompileStep::Run(v8::internal::wasm::AsyncCompileJob*, bool) [/opt/homebrew/bin/node]
  21. 15: 0x1027b3f14 v8::internal::wasm::AsyncCompileJob::CompileTask::RunInternal() [/opt/homebrew/bin/node]
  22. 16: 0x1022e66cc node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task> >) [/opt/homebrew/bin/node]
  23. 17: 0x1022e58f4 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/opt/homebrew/bin/node]
  24. 18: 0x1028da454 uv__async_io [/opt/homebrew/bin/node]
  25. 19: 0x1028e9fdc uv__io_poll [/opt/homebrew/bin/node]
  26. 20: 0x1028da874 uv_run [/opt/homebrew/bin/node]
  27. 21: 0x1022c6aa0 node::NodeMainInstance::Run() [/opt/homebrew/bin/node]
  28. 22: 0x10226d8c0 node::Start(int, char**) [/opt/homebrew/bin/node]
  29. 23: 0x18a195450 start [/usr/lib/system/libdyld.dylib]
  30. [1] 57806 abort npm run dev

原因:

Node 在新款的 Mac 的 M1 macOS 系统运行的不是很好。就比如有些脚本在建立在 arm64 上的 Node 时会崩溃。

可以执行以下代码检查电脑上的 node 是不是运行在 arm64 上:

  1. $ node
  2. Welcome to Node.js v12.21.0.
  3. Type ".help" for more information.
  4. >
  5. > process.arch
  6. 'arm64'

目前已经修复的Node版本:v15 及以上版本。

解决办法:

办法1:在 Rosetta 2 模式下用 nvm 安装 node

在 nvm github 官方库里的一个 issue 里有很好的解答:

 回答中写道:这种方式是只在需要的时候使用 Rosetta 模式,而不需要整个终端进入 Rosetta 模式。

什么是 Rosetta 2 模式?

简单来说,其实就是M1芯片在过渡期间苹果给出的对应 X86芯片的兼容性方案。

在终端输入 arch -x86_64 zsh 回车进入Rosetta 2模式,然后就可以用 nvm install 安装 node 了(安装之前要把之前安装在 arm64 上的 node 版本卸载了。)。

每次用 nvm 安装 node 新版本前都需要先进入 Rosetta 2 模式。

  1. $ nvm uninstall 14
  2. $ arch -x86_64 zsh
  3. $ nvm install 14

删除项目中原来的 node_modules,重新 npm i。

办法2: 升级node版本到已修复的版本。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/468631
推荐阅读
相关标签
  

闽ICP备14008679号