我正在尝试从 Node.js 连接到 JDBC 驱动程序。我按照此处的说明进行操作:
https://www.npmjs.com/package/jdbc
我从 Github 下载了该项目,并在项目目录中尝试安装它:
npm i --python="/usr/local/bin/python3.11" jdbc
然而,这并没有成功。我收到以下难以理解的错误:
me@me:~/PROJECTS/node-jdbc-master$ npm i --python="/usr/local/bin/python3.11" jdbc
npm WARN deprecated [email protected]: do not use this version, it is broken
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: lolex has been renamed to @sinonjs/fake-timers. No API changes made. Please use the new package instead
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: you are strongly encouraged to use other testing options
npm ERR! code 1
npm ERR! path /home/me/PROJECTS/node-jdbc-master/node_modules/java
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! make: Entering directory '/home/me/PROJECTS/node-jdbc-master/node_modules/java/build'
npm ERR! CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
npm ERR! nodejavabridge_bindings.target.mk:124: recipe for target 'Release/obj.target/nodejavabridge_bindings/src/java.o' failed
npm ERR! make: Leaving directory '/home/me/PROJECTS/node-jdbc-master/node_modules/java/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.11.0 found at "/usr/local/bin/python3.11"
npm ERR! gyp info spawn /usr/local/bin/python3.11
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/me/PROJECTS/node-jdbc-master/node_modules/java/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/me/.cache/node-gyp/17.9.0/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=/home/me/.cache/node-gyp/17.9.0',
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=/home/me/.cache/node-gyp/17.9.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/home/me/PROJECTS/node-jdbc-master/node_modules/java',
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! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../../nan/nan.h:2884:0,
npm ERR! from ../src/java.h:9,
npm ERR! from ../src/java.cpp:1:
npm ERR! ../../nan/nan_typedarray_contents.h: In constructor ‘Nan::TypedArrayContents<T>::TypedArrayContents(v8::Local<v8::Value>)’:
npm ERR! ../../nan/nan_typedarray_contents.h:34:43: error: ‘class v8::ArrayBuffer’ has no member named ‘GetContents’
npm ERR! data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
npm ERR! ^
npm ERR! make: *** [Release/obj.target/nodejavabridge_bindings/src/java.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Linux 4.4.0-146-generic
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/me/PROJECTS/node-jdbc-master/node_modules/java
npm ERR! gyp ERR! node -v v17.9.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! /home/me/.npm/_logs/2022-04-19T18_56_54_389Z-debug-0.log
me@me:~/PROJECTS/node-jdbc-master$
我在这里做错了什么?
我使用的Java版本不支持吗?
$ java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
某些节点模块未编译。它们是纯源代码,允许它们在不同的架构中工作。问题是:它们需要被编译。这就是 node-gyp 正在尝试做的事情。它依次调用“make”模块,该模块用于编译 C 代码。此时就需要合适的C编译库。你缺少那些。
从哪里获得这些可能很棘手。我通常下载并安装 C++ 运行时环境(只需 google 即可),这通常可以解决问题。我听说安装 Visual Studio 也可以。显然您需要的关键文件是 MSBuild.exe。
所以请确保你安装了正确版本的 python、node-gyp、make、C++(C++ 运行时,或者你可以尝试 g++ 模块,我从未使用过)。看起来“java”模块正在触发此过程,因此请检查 java 模块文档。
更多信息这里。