DB using node-adodb on an electron app : working fine in dev, but not on build

12 views Asked by At

I have an issue with my on going app : I'm creating a desktop app using Electron-Forge, with React on Frontend and NodeJS on Backend. I need to use an Access DB as my DB, so I'm using node-adodb.

Here's what my db.js looks like :

const path = require("path");
const { app } = require("electron");

//'use strict';
const ADODB = require("node-adodb");

const connection = ADODB.open(
  `Provider=Microsoft.ACE.Oledb.12.0;Data Source=${
    app.isPackaged
      ? path.join(`${__dirname}/../../../../../BDD/testBDD.accdb`)
      : path.join(`${__dirname}/../../../client/out/BDD/testBDD.accdb`)
  };`,
  false
);
module.exports = connection;

When I try to access to my db, with a simple query, it works perfectly fine on dev mode (npm start), but not when the app is built (npm run package), I have the following error :

Spawn C:\Windows\SysWOW64\cscript.exe error

I spend the last days looking for a solution online, but nothing helped me.. May be someone knows a way here ?

By advance sorry, I'm a begginer in dev, you might need other informations to help, if so, you can consult my github repository for more details : https://github.com/Pavol-69/oxalis

Thank you !

1

There are 1 answers

0
Paul Valy On

So.. I finally found the answer right after asking for help.. u_u'

I'll explain in case other are looking for this information : As explained in this topic - ms access db connection in node.js -, we need to not pack adodb.js in app.asar

To do that, on Electron Forge, you have to go in forge.config.js and add adodb.js as an exception to the app.asar in packagerConfig :

module.exports = {
  ...
  packagerConfig: {
    asar: true,
    extraResource: ["../server/node_modules/node-adodb/lib/adodb.js"], //where adodb.js is located in your app directory
  },
  ...
}

This way, adodb.js will appear in your ressources directory once packaged, out of app.asar :

   out
    |-client-win32-x64
       |-ressources
         |-app.asar
         |-adodb.js

When it's configured, you need to say where is this adodb.js when it's packaged in you db.js :

const path = require("path");
const { app } = require("electron");

//'use strict';
const ADODB = require("node-adodb");

// This if condition to add to locate adodb.js when it's packaged
if (app.isPackaged) {
   ADODB.PATH = "./resources/adodb.js";
}

const connection = ADODB.open(
  `Provider=Microsoft.ACE.Oledb.12.0;Data Source=${
    app.isPackaged
      ? path.join(`${__dirname}/../../../../../BDD/testBDD.accdb`)
      : path.join(`${__dirname}/../../../client/out/BDD/testBDD.accdb`)
  };`,
  false
);
module.exports = connection;

And now, if you package this way, tadaaa ! Build is working with Access DB !