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

Can't import (the CJS) electron-reload from ESM modules, due to use of deprecated CJS feature: module.parent #121

Open
mnmkay opened this issue Mar 5, 2024 · 2 comments

Comments

@mnmkay
Copy link

mnmkay commented Mar 5, 2024

Here is electron-reload's source use of module.parent

Here is discussion about module.parent's problem with being imported, import(CJS)

Here is deprecation commit that suggests testing require.main

To test, run a single-line ESM file from node: TEST.mjs:

import 'electron-reload'

Output

TypeError: Cannot read properties of undefined (reading 'filename')

@xcy960815
Copy link

I solve this problem like this:

import electronReloader from "electron-reloader";

if (process.env.NODE_ENV === "development") {
  try {
    module.path = __dirname;
    module.filename = __filename;

    electronReloader(module, { watchRenderer: true });
  } catch (err: any) {
    console.log(err);
  }
}

I don't know why (I think, webpack is causing this.) but when I run the program, the filename and dirname is not defined so I defined it hardly and it worked.

It's electron-reload, not electron-reloader. I have the same problem.

@kursattkorkmazzz
Copy link

I solve this problem like this:

import electronReloader from "electron-reloader";

if (process.env.NODE_ENV === "development") {
  try {
    module.path = __dirname;
    module.filename = __filename;

    electronReloader(module, { watchRenderer: true });
  } catch (err: any) {
    console.log(err);
  }
}

I don't know why (I think, webpack is causing this.) but when I run the program, the filename and dirname is not defined so I defined it hardly and it worked.

It's electron-reload, not electron-reloader. I have the same problem.

Oww you are right! Sorry guys :D I confused them.

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