-
Notifications
You must be signed in to change notification settings - Fork 21
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
require is not defined in ES module scope #68
Comments
It worked ! when i remove |
Maybe? |
Thanks for your help! but ,Still the same error |
By the way, I never run |
Realy?ummm,I try it again,Yes,I got the electron window when i remove |
Can you tell more about your environment? |
No require is used in the code |
I'm not from the team by the way 😁 Just wanted to help. I'm starting with Electron and Nuxt, had an issue with the preload, and solved it. All I've read on the internet mentions removing "type": "module" from package.json to get it working. Both Nuxt and Electron are ESM ready: So, do you want to get rid of the error, or you want to have your .js files with ESM imports instead of require? (will be playing with tsconfig.json to see if I find something) |
Thanks for your help again!I wrote the code in nuxt-electron(https://nuxt.com/modules/electron) |
Hmmm... 🤔 Edit: And I think the |
Stay tuned to electron-vite/vite-plugin-electron#186 |
My question is same to you,So,Did you solve it? |
Not yet. Will keep playing with the |
Thanks!! |
SolutionUpdate Edit: You'll get an error because of process.env.ROOT = path.join(process.cwd(), '..')
process.env.DIST = path.join(process.env.ROOT, 'dist-electron')
process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
? path.join(process.env.ROOT, 'public')
: path.join(process.env.ROOT, '.output/public')
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
const preload = path.join(process.env.DIST, 'preload.js') Solution Revisited |
|
Please, check your |
SOLUTIONIn As per the error shown, |
This worked! Thanks for the help. |
|
Your remove the |
That's not the problem.The following code runs in the development environment
|
That's a different issue. We are talking about ESM in this thread. Probably you need to check if your environment is DEV or PROD and use the appropriate path like Edit: I'm checking this issue. __dirname is not going to work in ESM in production and we are compiling to ESM. So we stick to Edit: I reached a dead end here. Can't make it work when building the .exe. Getting errors in DEV mode, and in PROD the Electron window is empty. |
when |
If we're trying to use ES Modules (ESM) in Electron we should have The problem is that the This is a little
|
Hey! Thanks for the feedback. Will try your solution. |
package.json {
- "type": "module",
} |
when run
nuxt dev && electron .
error
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 '[path]\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
help me,please!
The text was updated successfully, but these errors were encountered: