0

我正在尝试使用 npm 包kafka-streams但出现以下错误:

PS D:\Projects\POCs\kstreams-poc> npm install kafka-streams

> node-rdkafka@2.7.1 install D:\Projects\POCs\kstreams-poc\node_modules\node-rdkafka
> node-gyp rebuild


D:\Projects\POCs\kstreams-poc\node_modules\node-rdkafka>if not defined npm_config_node_gyp (node "C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:344:14)
gyp ERR! stack     at C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:365:16
gyp ERR! stack     at C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\virtual\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:302:5)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\virtual\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Projects\POCs\kstreams-poc\node_modules\node-rdkafka
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
npm WARN kstreams-poc@1.0.0 No description
npm WARN kstreams-poc@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-rdkafka@2.7.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-rdkafka@2.7.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

尝试了几件事:
1.安装了 windows-build-tools
2.安装了 python (2.7.16)
3.更新了节点 (v12.7.0)
4.安装了 Visual C++ 构建工具。

正如 Matt 所建议的,我也安装了 Visual C++ Build 工具。现在我遇到以下错误:

gyp info spawn args ]
gyp: binding.gyp not found (cwd: D:\Projects\POCs\kstreams-poc) 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 (C:\Users\virtual\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:344:16)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\virtual\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Projects\POCs\kstreams-poc
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok

更新:1
最后,我已经能够成功构建 node-gyp:

PS D:\Projects\POCs\test-kstream> node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@5.0.3
gyp info using node@12.7.0 | win32 | x64
gyp info find Python using Python version 2.7.16 found at "C:\Python27\python.exe"
gyp info find VS using VS2017 (15.9.28307.770) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python27\python.exe
gyp info spawn args [## Heading ##
gyp info spawn args   'C:\\Users\\virtual\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\Projects\\POCs\\test-kstream\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\virtual\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\virtual\\AppData\\Local\\node-gyp\\Cache\\12.7.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=C:\\Users\\virtual\\AppData\\Local\\node-gyp\\Cache\\12.7.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\virtual\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\Users\\virtual\\AppData\\Local\\node-gyp\\Cache\\12.7.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=D:\\Projects\\POCs\\test-kstream',
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   'D:\\Projects\\POCs\\test-kstream\\build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
Warning: Missing input files:
D:\Projects\POCs\test-kstream\build\..\build\Release\binding.node
gyp info ok

但是仍然在尝试安装 kafka-stream 时出现以下错误

d:\projects\pocs\test-kstream\node_modules\node-rdkafka\src\workers.cc(909): warning C4996: 'Nan::Callback::Call': was declared deprecated [
D:\Projects\POCs\test-kstream\node_modules\node-rdkafka\build\node-librdkafka.vcxproj]
  d:\projects\pocs\test-kstream\node_modules\nan\nan.h(1740): note: see declaration of 'Nan::Callback::Call'
d:\projects\pocs\test-kstream\node_modules\node-rdkafka\src\workers.h(42): warning C4996: 'Nan::Callback::Call': was declared deprecated (co
mpiling source file ..\src\admin.cc) [D:\Projects\POCs\test-kstream\node_modules\node-rdkafka\build\node-librdkafka.vcxproj]
  d:\projects\pocs\test-kstream\node_modules\nan\nan.h(1740): note: see declaration of 'Nan::Callback::Call' (compiling source file ..\src\a
  dmin.cc)
d:\projects\pocs\test-kstream\node_modules\node-rdkafka\src\admin.cc(93): warning C4996: 'v8::Object::Set': was declared deprecated [D:\Proj
ects\POCs\test-kstream\node_modules\node-rdkafka\build\node-librdkafka.vcxproj]
  c:\users\virtual\.node-gyp\12.7.0\include\node\v8.h(3365): note: see declaration of 'v8::Object::Set'
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:266:23)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Projects\POCs\test-kstream\node_modules\node-rdkafka
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

似乎 Kafka-streams 它试图使用 node-gyp 版本(v3.8.0),但我有

PS D:\Projects\POCs\test-kstream> node-gyp --version
v5.0.3

有什么办法可以让 kafka-streams 使用 node-gyp 版本(v5.0.3)

更新:2

做了一些更改,现在当我运行npm i kafka-streams它时,现在尝试获取 node-gyp v5.0.3。仍然失败:

gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\aftab.ahmed\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Projects\POCs\node_modules\node-rdkafka
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'D:\Projects\POCs\package.json'
npm WARN POCs No description
npm WARN POCs No repository field.
npm WARN POCs No README data
npm WARN POCs No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-rdkafka@2.7.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-rdkafka@2.7.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
4

2 回答 2

1

看起来它正在寻找一个 Visual Studio 版本来编译 C++。Error: Could not find any Visual Studio installation to use它建议你去这里:https ://github.com/nodejs/node-gyp#on-windows

这是您缺少的步骤:

  • 安装 Visual C++ 构建环境:Visual Studio 构建工具(使用“Visual C++ 构建工具”工作负载)或 Visual Studio 2017 社区(使用“使用 C++ 进行桌面开发”工作负载)
于 2019-07-27T14:52:43.310 回答
1

kafka-streams 包依赖于包装原生库的 node-rdkafka librdkafka。由于所有这些依赖关系,使用起来似乎kafka-streams有点棘手。我也在多台 Windows 机器和一台 Linux 机器上尝试过。

花了几天时间后,不知何故,我设法使用以下步骤安装了它。

  • 卸载 node.js(确保删除缓存 C:\Users\aftab.ahmed\AppData\Roaming\npm-cache)
  • 安装最新的 node.js(v10.16.0)。这也会安装 npm 版本 6.10.0。
  • 使用 npm install -g node-gyp@5.0.3 安装 node-gyp。
  • 安装 VC++/Visual Studio 2010 构建工具。
  • 将 12.0 版 VC++ 构建工具的路径添加到您的 Path 环境变量中。
  • 安装 Python 2.7.16(3.x 或更高版本将不起作用)。
  • 将 Python 2.7 的路径添加到 Path 环境变量。
  • 下载 Win32_OpenSSL_1.0.2p.exe 并使用所有默认值进行安装。

按照上面的步骤我们现在可以安装了kafka-streams

npm i kafka-streams

参考资料:
https ://github.com/Blizzard/node-rdkafka/issues/487

于 2019-07-31T05:13:02.387 回答