cawa-93 / vite-electron-builder

Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
MIT License
2.38k stars 259 forks source link

dynamic import() which is available in all CommonJS modules. #1017

Open xuya227939 opened 3 hours ago

xuya227939 commented 3 hours ago

Describe the bug

npm run compile

error

⨯ Unable torequiremoduleName=/Users/jiang/Desktop/vite-electron-builder-main/electron-builder.mjs message=require() of ES Module /Users/jiang/Desktop/vite-electron-builder-main/electron-builder.mjs not supported. Instead change the require of /Users/jiang/Desktop/vite-electron-builder-main/electron-builder.mjs to a dynamic import() which is available in all CommonJS modules.

To Reproduce

  1. npm run compile
cawa-93 commented 2 hours ago

What node version do you use?

xuya227939 commented 2 hours ago

node -v v20.14.0

@cawa-93

xuya227939 commented 1 hour ago

and macOS Version is 15.0.1 @cawa-93

cawa-93 commented 1 hour ago

Does it work on node v23 ?

xuya227939 commented 44 minutes ago

it's work, but why? @cawa-93

cawa-93 commented 41 minutes ago

That's because I tested it only on node v23 and did not realize I use experimental feature. In your case, you can simply rewrite electron-builder.mjs into electron-builder.cjs (and rewrite content from ES modules CommonJS modules). And it should work on node v20