Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Uncaught ReferenceError: __dirname is not defined when I try to import electron #1

Open
capaj opened this issue May 23, 2021 · 5 comments

Comments

@capaj
Copy link

capaj commented May 23, 2021

I get this when I try to add import such as import { ipcRenderer } from 'electron'; :

Uncaught ReferenceError: __dirname is not defined
    at node_modules/electron/index.js (index.js:4)
    at __require (chunk-KYLA5N2V.js?v=0feadafd:12)
    at dep:electron:1

Although electron is in externals for sure

I also tried adding this:

  optimizeDeps: {
    exclude: ['electron'],
  },

to my renderer.vite.config.
That resulted in error Uncaught SyntaxError: The requested module '/@fs/home/capaj/work-repos/subz-desktop/node_modules/electron/index.js?v=2d23cc12' does not provide an export named 'default'

Any idea how to resolve this issue?

@soulsam480
Copy link
Owner

Electron is in externals by default, Did you upgrade any dependency ?

@LiXiaoLongsgithub
Copy link

I also have this problem when I try to add import { ipcRenderer } from 'electron' .
can you solve this problem?
thanks
@soulsam480

@soulsam480
Copy link
Owner

Will check.

@soulsam480
Copy link
Owner

Hii @LiXiaoLongsgithub @capaj , the repo has been updated to latest upstream. Can you try the new template now ? If it's possible

@alexweber
Copy link

As far as I know you should import backend stuff in the preload package, there you can re-export and import from render to use.

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

No branches or pull requests

4 participants