electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.34k stars 494 forks source link

[ERR_MODULE_NOT_FOUND] [ESM] Vite doesn't bundle internal dependencies #3644

Open rtritto opened 2 weeks ago

rtritto commented 2 weeks ago

Pre-flight checklist

Electron Forge version

7.4.0

Electron version

31.0.1

Operating system

Windows 11

Last known working Electron Forge version

No response

Expected behavior

No error in console

Actual behavior

With ESM, the electron-squirrel-startup dependency can't be found if it's in dependencies (it works if I move it into devDependencies):

Note: I did a try with other dependencies such as react and solid-js and I got same issue.

Steps to reproduce

Repository: https://github.com/rtritto/template-electron-vite

Steps:

Additional information

No response

rtritto commented 1 week ago

@jdms754 what do you think about this issue?

jdms754 commented 1 week ago

@jdms754 what do you think about this issue?

I added import.meta.resolve('electron-squirrel-startup/package.json') anywhere in https://github.com/jdms754/forge-vite-bundler/blob/main/src/main.ts and was able to npm run start. I am on macOS Sonoma 14.5, but I am not sure that is the cause of the difference.

rtritto commented 1 week ago

I've already tried with import.meta.resolve('electron-squirrel-startup/package.json') (issue description). Maybe it's related to some settings in tsconfig.json:

jdms754 commented 6 days ago

I've already tried with import.meta.resolve('electron-squirrel-startup/package.json') (issue description). Maybe it's related to some settings in tsconfig.json:

Yes, looks like it's tsconfig.json. Why not set moduleResolution to node16 or bundler? You will also need to update module in the same file and you may have to make additional changes to your vite config files.

rtritto commented 6 days ago

I used the template created by @caoxiemeihao