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

Add ESM support #31

Open
BlackGlory opened this issue Dec 11, 2023 · 3 comments
Open

Add ESM support #31

BlackGlory opened this issue Dec 11, 2023 · 3 comments

Comments

@BlackGlory
Copy link

Electron 28 already has ESM support, but the library doesn't work in ESM yet.

Here's my current solution based on making a fake NodeModule:

const module = {
  filename: fileURLToPath(import.meta.url)
, children: []
}

Due to the lack of module.children, full ESM support may not be possible.

@innazh
Copy link

innazh commented May 3, 2024

@BlackGlory just to get some more detail, is this the code you'd have in index.mjs? Or what's exactly your solution here?

const module = {
  filename: fileURLToPath(import.meta.url)
  , children: []
}

try {
  require('electron-reloader')(module);
} catch { }

@nickyhajal
Copy link

@innazh Funnily enough, I was about to ask the same thing here but refreshed and saw your comment. So I think we're both working through this at the exact same time :)

I just tried this and it seems to work:

try {
	const module = {
		filename: fileURLToPath(import.meta.url),
		children: [],
	}
	const reloadPkg = await import('electron-reloader')
	reloadPkg.default(module)
} catch (e) {
	console.error(e)
}

@BlackGlory
Copy link
Author

@innazh I've stopped using this library, but my solution at the time should be similar to your code. Just read the source code of this library and make a fake module object suitable for it.

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

3 participants