在 M1 Mac 上安装 npm,您可能会因架构差异或缺少依赖项而遇到问题

问题描述 投票:0回答:1

将 mac book air 升级到 M1 芯片后,我在执行 npm i 时遇到以下错误

npm ERR! gyp info spawn args  '/Users/vishnu/Library/Caches/node-gyp/16.20.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/vishnu/Library/Caches/node-gyp/16.20.2',
npm ERR! gyp info spawn args  '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args  '-Dnode_lib_file=/Users/vishnu/Library/Caches/node-gyp/16.20.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args  '-Dmodule_root_dir=/Users/vishnu/work/flo-util/node_modules/canvas',
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! /bin/sh: pkg-config: command not found
npm ERR! gyp ERR! cwd /Users/vishnu/work/flo-util/node_modules/canvas
npm ERR! gyp ERR! node -v v16.20.2
npm ERR! gyp ERR! node-gyp -v v9.1.0
npm ERR! gyp ERR! not ok 
npm ERR! node-pre-gyp ERR! build error 
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node 
node.js macos npm
1个回答
0
投票

在 M1 Mac 上安装 npm,您可能会因架构差异或缺少依赖项而遇到问题。 这对我来说很有用,在命令下一一运行

softwareupdate --install-rosetta
arch -x86_64 brew install node@16
brew link --force --overwrite node@16

然后转到项目文件夹并运行以下命令

npm i
© www.soinside.com 2019 - 2024. All rights reserved.