Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging nodert in electron #5

Closed
ShafSpecs opened this issue Jun 5, 2024 · 9 comments
Closed

Packaging nodert in electron #5

ShafSpecs opened this issue Jun 5, 2024 · 9 comments

Comments

@ShafSpecs
Copy link

ShafSpecs commented Jun 5, 2024

Hello 馃憢, how is nodert packaged with electron? Everytime I package it normally and build it, then attempt to run the installed, native app, I get an error about missing imports. Using it in dev and preview works, but packaging it seems to break the package

@ShafSpecs
Copy link
Author

I am importing it normally btw:

import { devices } from '@xan105/nodert'

@ShafSpecs
Copy link
Author

The error:
image

@xan105
Copy link
Owner

xan105 commented Jun 5, 2024

It's pretty late so I can't check right now. But I just noticed that the actual filename has an uppercase char in its name
applicationmodel.js -> applicationModel.js (nb: auto generated files; didn't notice)
Maybe it does not work because asar is case sensitive ?

@xan105
Copy link
Owner

xan105 commented Jun 6, 2024

Ok so somehow applicationmodel.js had an uppercase char in its name on GitHub but not on my filesystem 馃 and I didn't notice until now.
Since I now use Github action to publish the package to npm, "that mistake" got push to the npm package as well.

I've updated the package (2.1.2 | 5572a3c); I believe this should fix your error. Let me know.

Sorry for the inconvenience.

@ShafSpecs
Copy link
Author

Ok so somehow applicationmodel.js had an uppercase char in its name on GitHub but not on my filesystem 馃 and I didn't notice until now. Since I now use Github action to publish the package to npm, "that mistake" got push to the npm package as well.

I've updated the package (2.1.2 | 5572a3c); I believe this should fix your error. Let me know.

Sorry for the inconvenience.

Thanks. It no longer throws errors, still opens as expected. But for some reason, doesn't work. I think that's a me thing though, would debug and get back to you :)

@ShafSpecs
Copy link
Author

I've updated the package (2.1.2 | 5572a3c); I believe this should fix your error. Let me know.

Still doesn't work when packaged.

I get this error now:

(node:17656) UnhandledPromiseRejectionWarning: TypeError: devices.geolocation.Geolocator is not a constructor
    at subscribeToGeolocation (file:///C:/Users/user/AppData/Local/Programs/project/resources/app.asar/out/main/index.js:15336:23)
    at file:///C:/Users/user/AppData/Local/Programs/project/resources/app.asar/out/main/index.js:15698:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
(node:17656) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

I am importing devices normally:

import { devices } from '@xan105/nodert'

And instantiating geolocation normally:

const geolocation = new devices.geolocation.Geolocator()

@ShafSpecs
Copy link
Author

Geolocator seems to be undefined in the packaged build. Maybe a *.node thing? Would debug

@xan105
Copy link
Owner

xan105 commented Jun 10, 2024

I do not know which build process / system you are using to package your Electron app;
but when using asar archive you need to leave native modules unpacked using the --unpack option.
eg: npx asar pack "/path/to/source" "/path/to/dest" --unpack *.node
cf: https://www.electronjs.org/docs/latest/tutorial/asar-archives#limitations-of-the-node-api

Native modules should thus end up in ./resources/app.asar.unpacked directory next to app.asar.
Hence this line in my .node file loader

).replace("app.asar", "app.asar.unpacked"); //electron asar friendly

@ShafSpecs
Copy link
Author

Fixed it. Thanks 鉂わ笍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants