question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It works perfectly on runtime node but not in asar

See original GitHub issue

I developed an react+Electron application with node-adodb on Windows. It works perfectly in development mode, but when packaging everything (create the .exe and other electron files), the connection.query got “Uncaught Fatal Exception”

Using node-adodb version 4.2.2 React 16.4.0 electron 2.0.5 electron-builder: 20.15.1

main.js code

ipcMain.on('read-cid', (event, obj) => {
  const connection = ADODB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\DB.mdb;')
  async function query() {
      try {
          const users = await connection.query(`SELECT top 1 id_birth, id_addr FROM IDBaseInfo  `)
          event.returnValue = users
      } catch (error) {
           event.returnValue = error
      }
  }
  query()
})

不打包成asar就运行良好,打包成asar,就会出现Uncaught Fatal Exception,请问有什么方法可以在打包成asar的情况下使用模块吗 谢谢!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
lega0208commented, Aug 2, 2018

Yeah, so I had this issue a few months ago and figure out the problem. Basically this. Packaged Electron projects don’t play well with child_process.spawn. And also cwd() doesn’t work properly in asar files, that may have also contributed. I forget.

But the workaround is the following:

  1. In your packager settings, add a glob that matches the node-adodb package to the asar.unpack setting.
  2. Go to line 13 of proxy.js and change it so that it matches the unpacked directory.

The way I did this was I changed require.resolve('./adodb') to require.resolve('./adodb').replace('app.asar', 'app.asar.unpacked')

I also published my own npm package to make things easier for myself, you can try it out if you want, and see if it works for you. It doesn’t use the latest version though so just be aware of that. Just don’t forget to add the unpacked setting or it won’t work.

npm i -S node-adodb-electronfork

Hope it works out for you. Cheers.

1reaction
HaveFcommented, Oct 11, 2018

Get everything work by a trick.

I use webpack.

  • In the main process add this before opening the BrowserWindow
const nodeEnv = process.env.NODE_ENV;

if(nodeEnv === 'development'){
  global.ADODB = require('node-adodb')
} else {
  let libPath = path.join(app.getAppPath(), 'node_modules/node-adodb').replace('app.asar', 'app.asar.unpacked')
  global.ADODB = require(libPath)
}
  • In the renderer process pick the value this way:
const ADODB = require('electron').remote.getGlobal('ADODB')

Btw, new Electron version does not work in the situation, I tried on 4.0.0-nightly.20181010

Cheers

REF: node.js - How can I bundle a precompiled binary with electron - Stack Overflow

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are files copied from Asar readonly? - Stack Overflow
The problem is that whenever the file is copied, it becomes readonly, and thus I can not write to it. Any way to...
Read more >
electron-asar-edge - npm
An edge connects two nodes. This edge connects Node.js and .NET. V8 and CLR/CoreCLR/Mono - in process. On Windows, MacOS, and Linux. image....
Read more >
electron builder not allowed to load local resource - You.com
I was not able to find any folder called dist packaged in the app.asar, so my conclusion was that the building process in...
Read more >
Supporting Remote Development and GitHub Codespaces
A guide to adding Visual Studio Code Remote Development and GitHub Codespaces support to extensions.
Read more >
Cannot connect to MongoDB on localhost using JDBC
Most likely your authSource is wrong. Try to simply remove it and the default admin will be used. It it stiĺl does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found