Open hamyyy opened 2 years ago
Though I am not experienced with Svelte, I would hazard to guess that require("stream");
isn't doing what it's expected to in your context since evidently Stream.Transform is showing up as undefined and things are unraveling from there.
A big clue should be that you said "in browser". Make sure you're resolving through Electron's node API and not the renderer process.
I just ran into this problem. I think this may have something to do with ESM loading and typescript, but I get very lost when it comes to module loading.
I was able to reproduce this exact error using Electron, Typescript, VueJS, and Quasar. I tried to reproduce the problem with https://github.com/serialport/electron-serialport, but that project worked fine.
I think the crux of the problem is when you introduce Typescript.
I found that if I take this project: https://github.com/electron/electron-quick-start-typescript and add import { SerialPort } from 'serialport'
, it fails. I don't get the same failure, but it is a starting point.
If you want to have a look at this exact failure, I can point you to my project.
I just found root cause of my problem. I was trying to import serialport inside the VueJS code and vite doesn't allow you to use native NodeJS code. The solution is to wrap the serial port code in electron-preload.ts which then makes it available through the window
global.
@BryanHunt can you post your final code? I have a similar problem, my solution was to use require instead of import, inside the main process. Even in the main process, I was unable to use import. Getting this error :
App threw an error during load
Error: No native build was found for platform=darwin arch=arm64 runtime=electron abi=116 uv=1 armv=8 libc=glibc node=18.15.0 electron=25.2.0
loaded from: /Users/maduhaime/_dev/typescript/quiz-machine/electron
at f.resolve.f.path (/Users/maduhaime/_dev/typescript/quiz-machine/electron/dist/main.js:6:12575)
at f (/Users/maduhaime/_dev/typescript/quiz-machine/electron/dist/main.js:6:11914)
at Object.<anonymous> (/Users/maduhaime/_dev/typescript/quiz-machine/electron/dist/main.js:8:2345)
at Module._compile (node:internal/modules/cjs/loader:1269:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1324:10)
at Module.load (node:internal/modules/cjs/loader:1124:32)
at Module._load (node:internal/modules/cjs/loader:965:12)
at f._load (node:electron/js2c/asar_bundle:2:13330)
at loadApplicationPackage (/Users/maduhaime/_dev/typescript/quiz-machine/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:121:16)
at Object.<anonymous> (/Users/maduhaime/_dev/typescript/quiz-machine/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:233:9)
I get the same error. I use react and vite. what can i do
Good. It does. It's just a little redundant.
@BryanHunt
vite doesn't allow you to use native NodeJS code.
How did you find this out? Do you have a reference that talks about it? I'm running into this with vite & ASP.NET and trying to come up with another workaround, but I don't think I understand exactly what's not allowed.
SerialPort Version
10.3.0
Node Version
v16.13.1
Electron Version
15.3.0
Platform
Microsoft Windows NT 10.0.22000.0 x64 (Windows 11)
Architecture
x64
Hardware or chipset of serialport
NA
What steps will reproduce the bug?
I'm using Svelte + Electron (scroll to bottom for more info).
My file contains
The error seems to appear when importing anything from
"@serialport/*"
.Serialport is imported into a
.svelte
file (Svelte component) using normal Svelte syntax as shown.What happens?
Error in browser:
What should have happened?
serialport imports correctly
Additional information
As mentioned, I am using Svelte + Electron.
Project created using this npx command (when creating choose svelte and typescript).
A quick google search tells me that the error is related to circular dependencies. I don't know how to fix it, but I'm hoping someone might be able to help.