-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
Vite Plugin with ESM support for main #3439
Comments
I found that I can override that setting in
I have another issue now though, as in esm __dirname is not available. This is needed to specify the index.html path and the preload file. I changed it to:
However, Vite replaces If I replace them with relative paths, it loads the files but warns it wants an absolute path for preload.js. Guessing some sort of |
+1. Thanks for your investigation! I wonder if you tried I'm brought here trying to use both I think I can slap an |
The combination of svelte + vite + electron + forge doesn't seem to work unless we have ESM support. |
You can try to this 👉 #3309 The next version of Vite plugin will be use |
Is this something that's planned? I'm hoping to use Forge with Svelte + Vite (not SvelteKit). |
The "horrid" workaround I suggested seems to be working for me. I've got |
Aweome! I haven't had a chance to try your suggestion but I'm starting a new project tomorrow and might mess around with it more. Hopefully the official support comes soon but good to know its coming by default soon! |
Fixed by #3468 |
thanks @caoxiemeihao! any ideas when #3468 might land in a release? |
Wait so I will be able to actually use Kinda want to use with SvelteKit, – but it only supports esm projects. |
Was this supposed to be fixed in the 7.3.0 release? This issue was closed, but even with running a fresh install Edit - Hmm yeah, looking through the current code, it doesnt look like theres any changes to the template to use esm and not cjs for main. It still uses mjs files for the config and main.config references |
@caoxiemeihao sorry to ping you, but just curious where this issue stands? |
Any update here? I cannot get esm / type: module to work with forge / vite / typescript. |
Strange that this issue is closed, as it appears @caoxiemeihao is still working on it: #3572 |
#3572 is just making some changes to the template, not a major upgrade. |
@caoxiemeihao yep, I confirmed this today via these application-side changes https://github.com/sparecycles/vite-svelte-tailwind-electron/compare/forge-7.3.0..forge-7.3.0-esm and then I think it's worth trying to apply the See #3506 (comment) (EDIT: preload.ts might need to be cjs still... broken) |
@sparecycles You gave me some inspiration and I updated the API design for migration to BTW, It can support - const { app } = reuiqire('electroon');
+ import { app } from 'electron'; |
This is still confusing. In the main branch vite template, there still seems to be a mix with mjs and I tried to modify it all manually based on the template, but vite still ended up generating main.js file with While building, vite generates a warning
and with What is the best way to create ESM-enabled vite project (without Typescript)? Tried to update devDependencies to
I guess, something differs a lot in main or I don't know how to install main branch in node_modules properly. |
Pre-flight checklist
Electron Forge version
7.2.0
Electron version
v28.0.0
Operating system
Windows 10 22H2
Last known working Electron Forge version
N/A
Expected behavior
I see that V28 brings ESM support (Hooray!). I'd like to switch my projects over but I'm having issues getting the Vite template to build. I successfully got a normal electron-forge app to build but using the vite template I cannot as it still converts it to cjs.
Actual behavior
Vite converts
main.js
to cjs, in which it then errors out because the package.json has been updated to include "type": "module".Steps to reproduce
yarn create electron-app test-esm-vite --template=vite
"type": "module",
topackage.json
forge.config.js
toexport default
src/index.js
to:./squirrel.js
vite.*.config.mjs
tovite.*.config.js
forge.config.js
paths forplugin-vite
to remove.mjs
Additional information
Looking through the vite plugin code, there is still a reference stating that Electron doesn't support ESM which is no longer true. Can this be updated?
Line 76 in file: https://github.com/electron/forge/blob/main/packages/plugin/vite/src/ViteConfig.ts
I tried overriding this in my defineConfig({}) but haven't had any luck:
I know this is an on going effort to update everything. I'd figure I'd bring it to attention since the code now says something that's untrue and because I can't figure out what the work around to override this.
The text was updated successfully, but these errors were encountered: