Electron not loading the correct native module


#1

Summary:

I’m trying to get npm “sqlite3” package to run on windows and electron is NOT trying to load the correct native module. It is trying to load ‘C:\electron\node_modules\sqlite3\lib\binding\node-v47-win32-ia32\node_sqlite3.node’. It seems like it should be loading ‘C:\electron\node_modules\sqlite3\lib\binding\electron-v0.36-win32-ia32\node_sqlite3.node’.

Details:

I’ve create a very simple electron app that tries to load the sqlite3 npm module. package.json has

{
  "name": "your-app",
  "version": "0.1.0",
  "main": "main.js",
  "devDependencies": {
    "electron-rebuild": "^1.1.3"
  },
  "dependencies": {
    "electron-prebuilt": "^0.36.8",
    "sqlite3": "^3.1.1"
  }
}

With the following index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    We are using node <script>document.write(process.versions.node)</script>,
    Chrome <script>document.write(process.versions.chrome)</script>,
    and Electron <script>document.write(process.versions.electron)</script>.
    <script>
      require('sqlite3');
    </script>
  </body>
</html>

After doing an npm install and node_modules\.bin\electron-rebuild.cmd -f I get the following 2 bindings in node_modules\sqlite3\lib\bindings:

  • electron-v0.36-win32-ia32
  • node-v47-win32-ia32

If I start electron I get the error: Uncaught Error: The system cannot find message text for message number 0x%1 in the message file for %2. \\?\C:\electron\node_modules\sqlite3\lib\binding\node-v47-win32-ia32\node_sqlite3.node.

However if I remove npm installed node-v47-win32-ia32 binding and rename the electron-v0.36-win32-ia32 to node-v47-win32-ia32 it works! So why isn’t electron trying to load electron-v0.36-win32-ia32 binding created by electron-rebuild?

Thanks,
~Jeff


How to use sqlite3 module with electron?
Compatible version with electron
#2

I’m pretty certain your running into what I also ran into. The issue is with out it looks for the compiled binding. There is more detail at: https://github.com/mapbox/node-sqlite3/issues/534 In particular this comment may help https://github.com/mapbox/node-sqlite3/issues/534#issuecomment-181523053


#3

Thanks for the help. It looks like the best way to fix it is to use the “node-pre-gyp workaround” in electron-rebuild and make that part of your grunt / gulp build process.

It is too bad that neither of those issues have been fixed so it just works.

~Jeff

References:

node-pre-gyp oustanding issues
node-pre-gyp issue: #177
node-pre-gyp issue: #187
(It says I can only put two links into the message so I’ll just referenced the issue numbers)