0
votes

For a angular2/electron learning app I use LinvoDB for persistent data storage based on the angular2-electron-starter seed that comes with two package.json one in root/ one in root/electron. After successful packaging the app.exe throws this error:

A JavaScript error occurred in the main process

Uncaught Exception:

Error: Cannot find module 'linvodb3'

So far I tried:

  • installing linvodb3 in / and /electron (npm install linvodb3 --save)
  • installing linvodb3 with --build-from-source
  • using electron-rebuild in both directories
  • apm install
  • multiple deinstallations and installations of various packages recommended at similar questions.

  • var LinvoDB = require('linvodb3'); in the according module and main.js

  • const LinvoDB = require('electron').remote.require('linvodb3');
  • var LinvoDB = require('linvodb3'); in index.html similar to the jQuery questions.

The only thing I read about and couldn't try was to set the NODE_PATH manually cause I couldn't find a file where it's specified.

1
Check if manually putting your node_modules/invodb3 folder inside your {buildfolder}/resources/app folder works for you. - Jens Habegger
@JensHabegger: Thank you very much, this is at least the first time at least the error changed, now it can't find the leveldown lib. Am I right that this is what the missing NODE_PATH would do? Is there a way to set it in this webpack/angular-cli version. I already thought it may is connected with the missing webpack.config there. - Patrick
I honestly havent figured out a way to let webpack manage these electron dependencies. Since I'm only really using electron-positioner, I have added the respective modules to my /src/, where it gets copied along as well. I'd be curious for any real solution though. - Jens Habegger

1 Answers

0
votes

As suggested by @JensHabegger the initial problem can be solved by copying the node_modules from the /electron subfolder to /dist, I do this by a script in the /package.json.

The deeper problem of the not found leveldown lib couldn't be fixed with electron-rebuilt but with a postinstall script in /electron/package.json:

"scripts": {
    "start": "electron .",
    "postinstall": "cd node_modules/leveldown && node-gyp rebuild --target=1.4.8 --arch=x64 --dist-url=https://atom.io/download/atom-shell"
  },