动态链接库 (DLL) 初始化例程失败。 无法导入leveldown
Error: A dynamic link library (DLL) initialization routine failed.
\\?\(Project Folder)\node_modules\leveldown\build\Release\leveldown.node: unable to import leveldown
at requireLeveldown ((Project Folder)\node_modules\pouchdb\lib\index.js:6206:12)
at PouchDB$5.LevelDownPouch ((Project Folder)\node_modules\pouchdb\lib\index.js:6406:17)
at new PouchDB$5 ((Project Folder)\node_modules\pouchdb\lib\index.js:2732:36)
at database_init ((Project Folder)\index.js:102:12)
at App.app.on ((Project Folder)\index.js:58:2)
at emitTwo (events.js:111:20)
at App.emit (events.js:191:7)
我在使用包
electron@2
和pouchdb-node@6
时遇到了类似的错误。
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\(Project Folder)\node_modules\leveldown\build\Release\leveldown.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
...
此外,对于
pouchdb-node@7
、pouchdb-node@8
,错误将如下所示:
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\(Project Folder)\node_modules\leveldown\prebuilds\win32-ia32\node.napi.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
...
对于
pouchdb-node@9
:
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\(Project Folder)\node_modules\level\node_modules\leveldown\prebuilds\win32-ia32\node.napi.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
...
这里的问题是
leveldown
(pouchdb-node
包依赖)DLL与您的环境不匹配。
对我来说解决方案是使用包electron-rebuild
为我的环境编译本机模块
。我的环境:
Windows 10 64-bit
node 8.9.3 32-bit
我的package.json
:
{
...
"scripts": {
"postinstall": "electron-rebuild"
},
"dependencies": {
"pouchdb-node": "^6.4.3"
},
"devDependencies": {
"electron": "^2.0.18",
"electron-rebuild": "^1.11.0"
}
}
命令后的结果npm install
:
> [email protected] install D:\(Project Folder)\node_modules\leveldown
> prebuild-install || node-gyp rebuild
> [email protected] postinstall D:\(Project Folder)\node_modules\electron
> node install.js
> (Project Name) postinstall D:\(Project Folder)
> electron-rebuild
√ Rebuild Complete
注意: electron-rebuild
有工作要求(例如:
PATH
中的 Python 2),但这是另一个问题的主题。我将在这里给出一些命令:
npm install --global --production [email protected]
npm install --global [email protected]
npm config set msvs_version 2017
注意:如果尝试编译pouchdb-node@9
,将会出现错误:
An unhandled error occurred inside electron-rebuild
...
d:\(Project Folder)\node_modules\leveldown\binding.cc(904): error C3861: 'napi_remove_env_cleanup_hook': identifier not found [D:\(Project Folder)\node_modules\leveldown\build\leveldown.vcxproj]
d:\(Project Folder)\node_modules\leveldown\binding.cc(915): error C3861: 'napi_add_env_cleanup_hook': identifier not found [D:\(Project Folder)\node_modules\leveldown\build\leveldown.vcxproj]
...
这是因为(
pouchdb-node@9
包依赖)的版本使用了
napi_add_env_cleanup_hook
和
napi_remove_env_cleanup_hook
Node.js API功能,在Node.js v8.12.0中引入了,所以解决方案是将Electron升级到
electron@3
使用 Node.js v10.2 底层,与使用 Node.js v8.9 的
electron@2
不同。
相关问题: