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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zeromq + vite + electron also fails (MAIN PROCESS! NOT RENDERER) #690

Open
devzzzero opened this issue Dec 31, 2024 · 1 comment
Open

zeromq + vite + electron also fails (MAIN PROCESS! NOT RENDERER) #690

devzzzero opened this issue Dec 31, 2024 · 1 comment
Labels

Comments

@devzzzero
Copy link

Describe the bug A clear and concise description of what the bug is.

This is similar to #676
I've given up trying to get zeromq working on the renderer side and instead using ipc to hack up the required communication hooks to the renderer from the main process, and managed to get the app limping along and running (on webpack).
However, I ran into what seems to be another blocker. When I package up the app, the resulting app dies because it's unable to find zeromq. Please see webpack/webpack#18995 (reply in thread)

I then tried to get electron+vite+react + zeromq to work, and ran into a strangely similar issue.

Reproducing If possible, provide a list of commands or a code sample that
reproduces the bug that you are observing. Otherwise please describe as much as
possible in which circumstances the bug can be observed.

I followed the instructions on https://electron-vite.github.io/guide/getting-started.html
to get a electron+vite+react.

I then added zeromq and verified that the tests do run using tsx
But ran into this one:

Uncaught Exception:
Error: Failed to load zeromq.js addon.node: ReferenceError: __dirname is not defined
ReferenceError: __dirname is not defined
    at findAddon (file:///home/jason/gui/electron-vite/Test.GUI/dist-electron/main.js:54:71)
    at file:///home/jason/gui/electron-vite/Test.GUI/dist-electron/main.js:81:15
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async loadApplicationPackage (file:///home/jason/gui/electron-vite/Test.GUI/node_modules/electron/dist/resources/default_app.asar/main.js:129:9)
    at async file:///home/jason/gui/electron-vite/Test.GUI/node_modules/electron/dist/resources/default_app.asar/main.js:241:9
    at findAddon (file:///home/jason/gui/electron-vite/Test.GUI/dist-electron/main.js:74:11)
    at file:///home/jason/gui/electron-vite/Test.GUI/dist-electron/main.js:81:15
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async loadApplicationPackage (file:///home/jason/gui/electron-vite/Test.GUI/node_modules/electron/dist/resources/default_app.asar/main.js:129:9)
    at async file:///home/jason/gui/electron-vite/Test.GUI/node_modules/electron/dist/resources/default_app.asar/main.js:241:9

Over on the webpack side, I managed to get past this issue (at least for the "run") by having zeromq listed as an external dependency.
but the packaged app fails.

On vite (this issue), I'm unable to get the app to run at all

Expected behavior A clear and concise description of what you expected to
happen.

I expe
Tested on

  • OS: [e.g. Ubuntu 18.04, Windows 10]
  • opensuse 15.5
  • ZeroMQ.js version: [e.g. 5.1.0, 6.0.0-beta.2]
  • 6.2.0
    TEST-package.json
@devzzzero
Copy link
Author

devzzzero commented Jan 3, 2025

electron-vite/vite-plugin-electron#265

Hi. So it's not enough to mark zeromq as external. Both webpack and vite fail the same way with the BUILT app (i.e. the result of npm run build)

FYI: this is in the main process in electron. NOT THE RENDERER.

D5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>npm run build

> [email protected] build
> tsc && vite build && electron-builder

vite v5.4.11 building for production...
transforming (1) index.htmlDeprecation [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

More info: https://sass-lang.com/d/legacy-js-api
transforming (7) src/App.tsxDeprecation [legacy-js-api]: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

More info: https://sass-lang.com/d/legacy-js-api
✓ 13 modules transformed.
rendering chunks (1)...computing gzip size (0)...computing gzip size (1)...computing gzip size (2)...computing gzip size (3)...computing gzip size (4)...dist/index.html                  0.47 kB │ gzip:  0.30 kB
dist/assets/react-CHdo91hT.svg   4.13 kB │ gzip:  2.05 kB
dist/assets/index-DLMJv6j3.css   1.43 kB │ gzip:  0.74 kB
dist/assets/index-B8Y9rJEj.js   25.79 kB │ gzip: 10.11 kB
✓ built in 377ms
vite v5.4.11 building for production...
transforming (1) electron/main.ts✓ 2 modules transformed.
rendering chunks (1)...computing gzip size (0)...computing gzip size (1)...dist-electron/main.js  1.92 kB │ gzip: 0.97 kB
✓ built in 29ms
vite v5.4.11 building for production...
transforming (1) electron/preload.ts✓ 1 modules transformed.
rendering chunks (1)...computing gzip size (0)...computing gzip size (1)...dist-electron/preload.mjs  0.35 kB │ gzip: 0.18 kB
✓ built in 17ms
  • electron-builder  version=24.13.3 os=5.14.21-150500.55.49-default
  • loaded configuration  file=/home/jason/gui/vite-bug/ZMQTest/electron-builder.json5
  • description is missed in the package.json  appPackageFile=/home/jason/gui/vite-bug/ZMQTest/package.json
  • author is missed in the package.json  appPackageFile=/home/jason/gui/vite-bug/ZMQTest/package.json
  • writing effective config  file=release/0.0.0/builder-effective-config.yaml
  • packaging       platform=linux arch=x64 electron=30.5.1 appOutDir=release/0.0.0/linux-unpacked
  • building        target=AppImage arch=x64 file=release/0.0.0/YourAppName-Linux-0.0.0.AppImage
  • application Linux category is set to default "Utility"  reason=linux.category is not set and cannot map from macOS docs=https://www.electron.build/configuration/linux
  • default Electron icon is used  reason=application icon is not set
\D5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>./release/0.0.0/YourAppName-Linux-0.0.0.AppImage 
A JavaScript error occurred in the main process
Uncaught Exception:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zeromq' imported from /tmp/.mount_YourApYAxnh0/resources/app.asar/dist-electron/main.js
    at packageResolve (node:internal/modules/esm/resolve:861:9)
    at moduleResolve (node:internal/modules/esm/resolve:934:18)
    at defaultResolve (node:internal/modules/esm/resolve:1176:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36)
  C-c C-cD5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>
D5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>
D5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>gdif
diff --git a/ZMQTest/vite.config.ts b/ZMQTest/vite.config.ts
index ece5fc3..4f6d60e 100644
--- a/ZMQTest/vite.config.ts
+++ b/ZMQTest/vite.config.ts
@@ -11,6 +11,14 @@ export default defineConfig({
       main: {
         // Shortcut of `build.lib.entry`.
         entry: 'electron/main.ts',
+        vite: {
+          build: {
+            rollupOptions: {
+              external: ['zeromq',
+                'electron-settings']  // 👈👈
+            },
+          },
+        },
       },
       preload: {
         // Shortcut of `build.rollupOptions.input`.
D5280:x86_64-Linux5:~/gui/vite-bug/ZMQTest>

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

No branches or pull requests

1 participant