yan-foto/electron-reload

fsevents get error "Module parse failed: Unexpected character '�' (1:0)"

jiereal opened this issue · 14 comments

What is the problem

in ./node_modules/electron-reload/node_modules/fsevents/fsevents.node

Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)

 @ ./node_modules/electron-reload/node_modules/fsevents/fsevents.js 13:15-41

node: 10.12.0
electron: 6.0.7

How to reproduce

just
require("electron-reload")(__dirname)

Additional information

This does not seem to be a problem of electron-reload. fsevents is a dependency of chokidar and the error somehow indicates file corruption locally.

Ratn commented

@jiereal , did you get the fix for it? I am also getting the same issue. I tried downgrading the fsevents package but that didn't help.

@Ratn how can I fix this when it's coming from fsevent? I cannot reproduce this on *nix.

also getting it: Node 12, Electron 8.0, Typescript (webpack + ts-loader)

@moarwick @Ratn I stumbled into the same problem today. A valid workaround for this problem is to add fsevents to your Webpack externals:

module.exports = {
  //...
  externals: {
    fsevents: "require('fsevents')"
  }
};

The issue is caused by this line const Native = require('./fsevents.node'); in fsevents.js. Since we're using webpack, the require that's being used here is the Webpack-equivalent of require() and not the one provided by node.

@pverscha why would you guys want to include electron-reload in your webpack?

@yan-foto I don't, I just stumbled into this thread and it was the only one that comes up on Google with this problem. It's completely fsevents related, but I just wanted to post a solution here to help fellow Googlers of the problem ;)

@pverscha thanks! I really appreciate that someone finally found the culprit here.

@pverscha Just gave you a tip through Brave: see here. I have no affiliation/understand not everyone's onboard with them, but I think it's nice to be able to show some appreciation for these kinds of answers/would like to use it for stuff like this more.

@Didericis Thanks! I'm not sure how that works though? I didn't have a Brave account (made one just now).

@pverscha Sure thing! Once you create a publisher/creator account, you should see an "add channel" option for github. Once you link your brave account with your github account/verify that you own the github account, it should work/you'll see a tip there. On my end I just clicked a little icon Brave added to your comment.

Screen Shot 2020-05-27 at 9 32 44 PM

I also encountered this problem yesterday when I try to require chokidar module in my vue-cli3 with electron-builder project. And this error only occurs on Mac OS. After trying all the above methods, they finally failed.

Since the problem is caused by const Native = require('fsevents.node'); in fsevents.js
I accidentally tried to change require('fsevents.node') to window.require('fsevents.node') and then he worked magically.

Thanks @pverscha . For my case both your solution or setting:

module.exports = {
  //...
  externals: ['fsevents'],
};

Solved the problem for me.

use node-loader.