Terry Chen
Terry Chen

Reputation: 469

A dynamic link library (DLL) initialization routine failed in electron with nodegit

When I use nodegit in electron, I got the error when I start the app:

App threw an error during load

Error: A dynamic link library (DLL) initialization routine failed.

\?\D:\Electron\hello\node_modules\nodegit\build\Release\nodegit.node

at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)

at Object.Module._extensions..node (internal/modules/cjs/loader.js:740:18)

...

I can use nodegit in nodejs successfully, but failed in electron.

Even I added .npmrc file with content below, it's still faield.

runtime = electron
target = 1.2.8
target_arch = x64
disturl = https://atom.io/download/atom-shell

Does anyyone know how to fix it in electron? My environment is windows 10 x64 with vs 2017, node 10.13, electron 3.010

Upvotes: 2

Views: 2865

Answers (3)

Sarang Kakkoth
Sarang Kakkoth

Reputation: 489

First confirm if global node version matches with the project one. Some projects require specific version hence first delete other node and install required node version and project dependencies. Try below solutions to solve the errors as same worked for me

  1. Clean up node modules [ https://medium.com/@mariokandut/how-to-clean-up-node-modules-5aed676156db ] and rebuild the project. It rebuilds node_modules folder
  2. Since it is an electron app try yarn electron-rebuild. For more info on yarn refer " https://www.digitalocean.com/community/tutorials/how-to-install-and-use-the-yarn-package-manager-for-node-js "
  3. If electron rebuild fails check if "Visual C++ Build Environment" are installed. Refer https://stackoverflow.com/a/61252536/9558119 for same.
  4. Rerun electron rebuild and then run build as per your project

Upvotes: 1

kursun
kursun

Reputation: 284

From this link:

The most common issue though is that the component was not properly installed, so that some of its dependencies are not available.

Upvotes: 0

no1spirite
no1spirite

Reputation: 638

I had the same problem with another node package using electron 3.0.6 and eventually got it working.

Try these:

  1. Make sure the packages are listed under the dependencies and not devDependencies in the package.json

  2. Add this "electron-rebuild --force node-gyp rebuild --target=3.0.6 --arch=x64" to postinstall under the scripts section. I ended up with this in my packages.json (my DLL error was for "printer")

    {
        "name": "myproject",
        "version": "1.0.0",
        "main": "main.js",
        "scripts": {
            "postinstall": "electron-rebuild --force node-gyp rebuild --target=3.0.6 --arch=x64",
            "start": "electron ."
        },
        "dependencies": {
           "@types/node": "^10.12.18",
           "electron-rebuild": "1.8.2",
           "electron": "3.0.6",
           "printer": "0.2.2"
        },
        "devDependencies": {
             ...
        }
    }
    

See here for more info

Hope this helps someone

Upvotes: 0

Related Questions