我目前正在开发一个 Node.js 项目,在尝试使用
npm install
安装必要的包时遇到了问题。在安装过程中,我收到了某些软件包的多个弃用警告,表明它们不再维护或应该升级。此外,安装失败并出现与 x509
软件包相关的错误,该错误似乎涉及 node-gyp
和编译问题。
尽管安装了正确版本的 Node.js 和 npm,但本机模块的构建过程失败,导致多个编译错误。这阻碍了我的进步,我不确定如何有效地解决这些问题。
我尝试检查软件包与我的 Node.js 版本的兼容性,但错误仍然存在。我将非常感谢有关如何解决弃用警告和安装错误的任何指导。
警告:
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]: node-webcrypto-ossl has been deprecated. This module was created in 2015 because at the time the Node team did not feel the need to have two crypto interfaces and they already had one before WebCrypto was defined.
错误信息:
npm error path /Users/rohail/Documents/Github/node-version-to-20/node_modules/x509
npm error command failed
npm error command sh -c node-gyp rebuild
npm error CXX(target) Release/obj.target/x509/src/addon.o
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | darwin | x64
npm error gyp info find Python using Python version 3.10.5 found at "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
npm error gyp info spawn /Library/Frameworks/Python.framework/Versions/3.10/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args '/Users/rohail/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '-f',
npm error gyp info spawn args 'make',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/rohail/Documents/Github/node-version-to-20/node_modules/x509/build/config.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/rohail/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/common.gypi',
npm error gyp info spawn args '-Dlibrary=shared_library',
npm error gyp info spawn args '-Dvisibility=default',
npm error gyp info spawn args '-Dnode_root_dir=/Users/rohail/Library/Caches/node-gyp/22.12.0',
npm error gyp info spawn args '-Dnode_gyp_dir=/Users/rohail/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp',
npm error gyp info spawn args '-Dnode_lib_file=/Users/rohail/Library/Caches/node-gyp/22.12.0/<(target_arch)/node.lib',
npm error gyp info spawn args '-Dmodule_root_dir=/Users/rohail/Documents/Github/node-version-to-20/node_modules/x509',
npm error gyp info spawn args '-Dnode_engine=v8',
npm error gyp info spawn args '--depth=.',
npm error gyp info spawn args '--no-parallel',
npm error gyp info spawn args '--generator-output',
npm error gyp info spawn args 'build',
npm error gyp info spawn args '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error gyp info spawn make
npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error In file included from ../src/addon.cc:5:
npm error In file included from ../include/x509.h:7:
npm error In file included from ../node_modules/nan/nan.h:174:
npm error ../node_modules/nan/nan_callbacks.h:55:23: error: no member named 'AccessorSignature' in namespace 'v8'
npm error typedef v8::Local<v8::AccessorSignature> Sig;
npm error ~~~~^
npm error In file included from ../src/addon.cc:5:
npm error In file included from ../include/x509.h:7:
npm error ../node_modules/nan/nan.h:2536:8: error: no matching member function for call to 'SetAccessor'
npm error tpl->SetAccessor(
npm error ~~~~~^~~~~~~~~~~
npm error /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/v8-template.h:1055:8: note: candidate function not viable: no known conversion from 'v8::AccessControl' to 'v8::PropertyAttribute' for 5th argument
npm error void SetAccessor(
npm error ^
npm error /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/v8-template.h:1049:8: note: candidate function not viable: no known conversion from 'imp::NativeGetter' (aka 'void (*)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &)') to 'v8::AccessorGetterCallback' (aka 'void (*)(Local<v8::String>, const PropertyCallbackInfo<v8::Value> &)') for 2nd argument
npm error void SetAccessor(
npm error ^
npm error In file included from ../src/addon.cc:5:
npm error In file included from ../include/x509.h:7:
npm error In file included from ../node_modules/nan/nan.h:2884:
npm error ../node_modules/nan/nan_typedarray_contents.h:34:43: error: no member named 'GetContents' in 'v8::ArrayBuffer'
npm error data = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
npm error ~~~~~~~~^
npm error In file included from ../src/addon.cc:4:
npm error In file included from ../include/addon.h:4:
npm error In file included from /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/node.h:73:
npm error In file included from /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/v8.h:24:
npm error In file included from /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/v8-array-buffer.h:12:
npm error /Users/rohail/Library/Caches/node-gyp/22.12.0/include/node/v8-local-handle.h:269:5: error: static_assert failed due to requirement 'std::is_base_of<v8::Value, v8::Data>::value' "type check"
npm error static_assert(std::is_base_of<T, S>::value, "type check");
npm error ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm error ../node_modules/nan/nan_callbacks_12_inl.h:175:20: note: in instantiation of function template specialization 'v8::Local<v8::Value>::Local<v8::Data>' requested here
npm error cbinfo(info, obj->GetInternalField(kDataIndex));
npm error ^
npm error 4 errors generated.
npm error make: *** [Release/obj.target/x509/src/addon.o] Error 1
npm error gyp ERR! build error
npm error gyp ERR! stack Error: `make` failed with exit code: 2
npm error gyp ERR! stack at ChildProcess.<anonymous> (/Users/rohail-invozone/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:216:23)
npm error gyp ERR! System Darwin 21.5.0
npm error gyp ERR! command "/Users/rohail/.nvm/versions/node/v22.12.0/bin/node" "/Users/rohail-invozone/.nvm/versions/node/v22.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm error gyp ERR! cwd /Users/rohail-invozone/Documents/Github/node-version-to-20/node_modules/x509
npm error gyp ERR! node -v v22.12.0
npm error gyp ERR! node-gyp -v v10.2.0
npm error gyp ERR! not ok
环境
package.json 文件
"name": "version-to-20",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^1.7.9",
"cors": "^2.8.5",
"express": "^4.21.2",
"express-rate-limit": "^7.4.1",
"got": "^14.4.5",
"x509": "git+https://github.com/lvhdev/node-x509"
}
}
您在安装过程中遇到的错误与编译本机模块(例如,
x509
)的问题有关,如提到node-gyp
的错误消息所示
错误日志指出了过时或已弃用的软件包的多个问题,例如
uuid
和 node-webcrypto-ossl
。考虑将这些包更新到与您的 Node.js 版本兼容的最新版本。
运行以下命令来更新所有依赖项:
npm update
像
x509
这样的原生模块需要某些构建工具来编译。确保您已安装所需的工具:
对于 macOS:您需要 Xcode 命令行工具。运行:
xcode-select --install
对于 Windows:通过运行以下命令确保安装了 Windows 构建工具:
npm install --global --production windows-build-tools
对于 Linux:使用以下命令安装所需的构建依赖项:
sudo apt-get install -y build-essential
确保您拥有构建工具后,您可以尝试重建
x509
模块:
npm rebuild x509
node-gyp
兼容性您的 Node.js 版本 (v22.12.0) 可能与您拥有的
node-gyp
版本不完全兼容。考虑将您的 Node.js 版本降级到您正在使用的模块更好支持的版本。 Node.js LTS 版本(例如 16.x 或 18.x)通常对于构建本机模块更稳定。
要使用
nvm
切换节点版本,您可以运行:
nvm install 16
nvm use 16
然后,尝试再次运行
npm install
。
x509
模块兼容性您使用的
x509
模块似乎是直接从 GitHub 存储库安装的。验证它是否得到积极维护并与您的 Node.js 版本兼容。如果存储库已过时,请考虑使用更新的替代方案或向维护人员寻求建议。
node-gyp
您可能还想确保
node-gyp
是最新的。尝试全局升级:
npm install -g node-gyp
要解决与
uuid
和 node-webcrypto-ossl
相关的弃用警告,您可以:
package.json
中这些软件包的版本。进行任何更改后,运行:
npm install