NPM 安装 node-rdkafka 失败,出现 node-gyp 重建错误。

10 浏览
0 Comments

NPM 安装 node-rdkafka 失败,出现 node-gyp 重建错误。

我正在尝试使用npm安装node-rdkafka,但出现以下错误:

  • OS: macOS Catalina 10.15.7
  • node版本:10.16.3(也尝试过8.x、12.x和13.x)通过nvm安装

/Users/VMac/.nvm/versions/node/v10.16.3/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin/node-gyp: line 5: /usr/local/lib/node_modules/node-gyp/bin/node-gyp.js: No such file or directory
npm WARN kafka-log-parser@1.0.0 No repository field.
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! node-rdkafka@2.7.0 install: `node-gyp rebuild`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the node-rdkafka@2.7.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/VMac/.npm/_logs/2020-09-30T14_35_01_271Z-debug.log

当我尝试使用npm install -g node-gyp安装node-gyp并运行node-gyp rebuild时,出现以下错误:

gyp info it worked if it ends with ok
gyp info using node-gyp@7.1.0
gyp info using node@10.16.3 | darwin | x64
gyp info find Python using Python version 3.8.3 found at "/usr/local/anaconda3/bin/python3"
gyp info spawn /usr/local/anaconda3/bin/python3
gyp info spawn args [ '/Users/VMac/.nvm/versions/node/v10.16.3/lib/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/VMac/Documents/VMAC/Code/GIT/kafka-log-simulator/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/VMac/.nvm/versions/node/v10.16.3/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/VMac/Library/Caches/node-gyp/10.16.3/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/VMac/Library/Caches/node-gyp/10.16.3',
gyp info spawn args   '-Dnode_gyp_dir=/Users/VMac/.nvm/versions/node/v10.16.3/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/VMac/Library/Caches/node-gyp/10.16.3/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/VMac/Documents/VMAC/Code/GIT/kafka-log-simulator',
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: binding.gyp not found (cwd: /Users/VMac/Documents/VMAC/Code/GIT/kafka-log-simulator) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/VMac/.nvm/versions/node/v10.16.3/lib/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/Users/VMac/.nvm/versions/node/v10.16.3/bin/node" "/Users/VMac/.nvm/versions/node/v10.16.3/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/VMac/Documents/VMAC/Code/GIT/kafka-log-simulator
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok

我也尝试了xcode-select --install但没有运气。

您有什么建议来解决这个问题并在我的mac上成功安装node-rdkafka吗?

admin 更改状态以发布 2023年5月22日
0
0 Comments

在尝试各种在线选项后,我找不到正确的解决方案。所以,这是我做的且有效的方法:

  1. 按照此处的说明卸载node

    如果您使用Homebrew,请运行

    brew uninstall node 
    

    如果需要,使用--force--ignore-dependencies

  2. 运行node -v。如果您仍然看到版本信息,请按此处的说明操作

  3. 我还想从我的机器上删除nvm。因此,我删除了~/.nvm文件夹。但是,我仍然看到nvm版本。要完全清理,请从~/.bashrc~/.zshrc中删除任何引用

我意识到我有两个版本的node:

  1. 手动安装的
  2. 使用Homebrew安装的

在此之后,我只安装了nvm(不安装node或npm)。

brew install nvm

然后使用

nvm install  

安装所需的node和npm版本,这解决了我的node-gyp错误

0
0 Comments

在自己碰到这个问题并尝试了两个答案提出的解决方案后均未成功,这是对我有效的解决方法,而不需要卸载节点。

TL:DR

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
npm install node-rdkafka

此后我能够无任何问题地安装node-rdkafka

建议按照 这里的建议删除CommandLineTools并重新安装,因为当我尝试运行xcode-select --install时,我会得到以下消息:

xcode-select: error: 命令行工具已安装,请使用“软件更新”安装更新

0