GitSquared / node-geolite2-redist

Redistribution of MaxMind GeoLite2 GeoIP databases as an npm library
https://gitsquared.github.io/node-geolite2-redist/
Other
81 stars 18 forks source link

hints for using this in electron app? error: ".mmdb not found in app.asar" #8

Closed cyphunk closed 4 years ago

cyphunk commented 4 years ago

Hi, perhaps this intentional but when using this lib in an electron application the download of updated database appears to fail with error (on linux ubuntu 18.04lts):

Error: ENOENT, node_modules/geolite2-redist/dbs-tmp/GeoLite2-Country.mmdb not found in /app/resources/app.asar
    at createError (electron/js2c/asar.js:111:17)
    at Object.module.<computed> [as open] (electron/js2c/asar.js:179:23)
    at WriteStream.open (internal/fs/streams.js:289:6)
    at new WriteStream (internal/fs/streams.js:269:10)
    at Object.createWriteStream (fs.js:1807:10)
    at Object.<anonymous> (/app/resources/app.asar/node_modules/geolite2-redist/scripts/download-helper.js:82:21)
    at Object.emit (events.js:228:7)
    at Object.[processEntry] (/app/resources/app.asar/node_modules/tar/lib/parse.js:224:12)
    at Object.[nextEntry] (/app/resources/app.asar/node_modules/tar/lib/parse.js:235:36)
    at Object.[consumeHeader] (/app/resources/app.asar/node_modules/tar/lib/parse.js:204:32)
Emitted 'error' event on WriteStream instance at:
    at internal/fs/streams.js:294:12
    at electron/js2c/asar.js:26:28
    at processTicksAndRejections (internal/process/task_queues.js:76:11) {
  code: 'ENOENT',
  errno: -2
}
GitSquared commented 4 years ago

This isn't intentional, the lib was made for an electron app. Are you using webpack or electron-forge? Make sure that node_modules/geolite2-redist/ is fully included in your asar archive, or perhaps exclude the dependency from the archive altogether (depending ont the build system, you might need to mark it as "unpacked" or "native")

cyphunk commented 4 years ago

I'm not sure. Packing into a tar.gz. Excerpts from package.json (source):

  "scripts": {
    "dist:linux": "electron-builder --linux",
  },
  "postinstall": "electron-builder install-app-deps",
  "build": {
    "linux": {
      "target": [
        "tar.gz"
      ],

But based on your advice I think I can resolve the issue later when I have a moment to examine more closely.

thanks!

GitSquared commented 4 years ago

The target packaging is a different thing. Electron apps bundle all their code and dependencies in an asar archive, which is then packed into whatever target you have (tar.gz, binaries, etc). More info.