Reputation: 337
A dynamic link library (DLL) initialization routine failed. unable to import 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)
Upvotes: 4
Views: 442
Reputation: 949
I faced similar error when working with packages electron@2
and 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)
...
Also, for pouchdb-node@7
, pouchdb-node@8
the error will look like this:
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)
...
And for 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)
...
The problem here is that the leveldown
(pouchdb-node
package dependency) DLL does not match your environment.
Solution for me was to compile the native module for my environment using package electron-rebuild
.
My environment:
Windows 10 64-bit
node 8.9.3 32-bit
My package.json
:
{
...
"scripts": {
"postinstall": "electron-rebuild"
},
"dependencies": {
"pouchdb-node": "^6.4.3"
},
"devDependencies": {
"electron": "^2.0.18",
"electron-rebuild": "^1.11.0"
}
}
Result after command 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
Note: electron-rebuild
has requirements to work (for example: Python 2 in PATH
), but that's a topic for another question. I will just give some commands here:
npm install --global --production [email protected]
npm install --global [email protected]
npm config set msvs_version 2017
Note: If you try to compile for pouchdb-node@9
, there will be an error:
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]
...
That's because the version of [email protected]
(pouchdb-node@9
package dependency) use napi_add_env_cleanup_hook
and napi_remove_env_cleanup_hook
Node.js API features, introduced in Node.js v8.12.0, so the solution is to upgrade Electron to electron@3
that uses Node.js v10.2 underhood, unlike electron@2
which uses Node.js v8.9.
Related questions:
Upvotes: 0