ESM not working with new electron
13OnTheCode opened this issue · 1 comments
13OnTheCode commented
Electron now has esm builtin and when I tried it with that I get:
PS C:\Users\13\Developer\electron-vite-project> pnpm run dev
> electron-vite-project@0.0.0 dev C:\Users\13\Developer\electron-vite-project
> vite
vite v4.5.0 building for development...
watching for file changes...
vite v4.5.0 building for development...
watching for file changes...
VITE v4.5.0 ready in 362 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h to show help
build started...
build started... (x2)
✓ 1 modules transformed.
✓ 1 modules transformed. (x2)
dist-electron/main.js 1.54 kB │ gzip: 0.69 kB
built in 124ms.
dist-electron/preload.js 2.70 kB │ gzip: 1.10 kB
built in 127ms.
App threw an error during load
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Users\13\Developer\electron-vite-project\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///C:/Users/13/Developer/electron-vite-project/dist-electron/main.js:2:18
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
caoxiemeihao commented