Skip to content
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

__dirname is not defined in ES module scope #258

Open
ParadiseWitch opened this issue Nov 3, 2024 · 1 comment
Open

__dirname is not defined in ES module scope #258

ParadiseWitch opened this issue Nov 3, 2024 · 1 comment

Comments

@ParadiseWitch
Copy link

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

@foxypiratecove37350
Copy link

__dirname is a CommonJS feature, you can replicate it in ESM using that:

import path from 'path'

const __dirname = path.dirname(new URL(import.meta.url).pathname)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants