I'm trying to build desktop app using Electron JS + React JS + Vite by using command (npm i electron-vite@latest
)
It works fine, now there is a need to communicate to serialport, so installed (npm i serialport
)node js seripaport , when I try to import serial port library and start launch application using (npm run dev
)
package.json:
"scripts": {
"dev": "vite",
"build": "tsc && vite build && electron-builder",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
App threw an error during load:
ReferenceError: __dirname is not defined in ES module scope
An I try to build a app without vite, it works fine with serialport
Is there any idea why it doesn't work with Vite but works without Vite?