iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
620 stars 210 forks source link

Core electron + core backend ESM #7293

Open hl662 opened 3 weeks ago

hl662 commented 3 weeks ago

Notables:

Note: tsc does not add .js extensions to extensionless imports (unlike Vite :( ), so had to add .js at the end of our relative import paths in DTA's backend.

hl662 commented 2 weeks ago

Pausing work on this PR for now, but documenting the work so far:

Image of the runtime issue: image

GytisCepk commented 2 weeks ago

I haven't dug into why the preload script is not being able to be loaded - everything does point to the backend being able to find ElectronPreload.mjs though (there was a prior runtime error saying it couldn't find the file).

ESM is not supported for preload script if sandbox is enabled (Electron ESM support matrix). If we plan to drop CJS from both backend and frontend code for Electron, we'll still need to transpile preload script to CJS.

GytisCepk commented 2 weeks ago

I haven't dug into the __dirname is not defined error, but it pops up on the frontend side of the electron app, suggesting that our vite.config.js needs to be updated to use electron's ESM version, rather than the CJS version.

Isn't __dirname only available in CJS ? __dirname Node.js docs