electron-vite / vite-plugin-electron

:electron: Electron⚡️Vite core repo
https://github.com/electron-vite
MIT License
691 stars 56 forks source link

__dirname is not defined in ES module scope #258

Open ParadiseWitch opened 2 weeks ago

ParadiseWitch commented 2 weeks ago

I used the playwright times error on the electron main thread:

App threw an error during load
ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '...\my-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:///.../my-electron-vite-project/dist-electron/main.js:2187:136
    at file:///.../my-electron-vite-project/dist-electron/main.js:88:33
    at file:///.../my-electron-vite-project/dist-electron/main.js:8292:133
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async loadApplicationPackage (file:///.../my-electron-vite-project/node_modules/electron/dist/resources/default_app.asar/main.js:129:9)
    at async file:///.../my-electron-vite-project/node_modules/electron/dist/resources/default_app.asar/main.js:241:9

minimum-reproduction