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

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

Closed
jiereal opened this issue Oct 4, 2019 · 14 comments
Closed

Comments

@jiereal
Copy link

jiereal commented Oct 4, 2019

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

@yan-foto
Copy link
Owner

yan-foto commented Oct 4, 2019

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.

@yan-foto yan-foto closed this as completed Oct 4, 2019
@Ratn
Copy link

Ratn commented Jan 3, 2020

@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.

@yan-foto
Copy link
Owner

yan-foto commented Jan 3, 2020

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

@moarwick
Copy link

moarwick commented Feb 14, 2020

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

@pverscha
Copy link

pverscha commented Feb 20, 2020

@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.

@yan-foto
Copy link
Owner

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

@pverscha
Copy link

@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 ;)

@yan-foto
Copy link
Owner

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

@Didericis
Copy link

@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.

@pverscha
Copy link

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

@Didericis
Copy link

@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

@mordom0404
Copy link

mordom0404 commented Mar 30, 2021

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.

undergroundwires added a commit to undergroundwires/privacy.sexy that referenced this issue Dec 31, 2021
Upgrade to v5.x using `vue upgrade --next`.

Update `vue.config.js` to import and use `defineConfig`, because it
provides type safety and created by Vue CLI 5 as default.

Vue CLI 5.x upgrades from webpack 4 to 5. It causes some issues that this
commit attemps to fix:

1. Fail due to webpack resolving of Ace.
   Third-party dependency (code editor) Ace uses legacy `file-loader`
   for webpack resolving. It's not supported in webpack 5. So change it
   with manual imports.
   Refs: ajaxorg/ace-builds#211, ajaxorg/ace-builds#221.

2. Wehpack drops polyfilling node core modules (`path`, `fs`, etc.).
   Webpack does not polyfill those modules by default anymore. This is
   good because they did not need browser polyfilling as they are
   used in desktop version only and resolved already by Electron.
   To resolve errors (using webpack recommendations):
    - Add typeof check around `process` variable.
    - Tell webpack explicitly to ignore used node modules.

3. Fail due to legacy dependency of vue-cli-plugin-electron-builder.
   This plugin is used for electron builds and development. It still
   uses webpack 4 that leads to failed builds.
   Downgrading `ts-loader` to latest version which has support for
   `loader-utils` solves the problem (TypeStrong/ts-loader#1288).
   Related issue: nklayman/vue-cli-plugin-electron-builder#1625

4. Compilation fails due to webpack loading of `fsevents` on macOS.
   This happens only when running `vue-cli-service test:unit` command
   (used in integration tests and unit tests). Other builds work fine.
   Refs: yan-foto/electron-reload#71,
     nklayman/vue-cli-plugin-electron-builder#712,
     nklayman/vue-cli-plugin-electron-builder#1333
@undergroundwires
Copy link

undergroundwires commented Dec 31, 2021

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

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

Solved the problem for me.

@dreamthen
Copy link

use node-loader.

nakahashi added a commit to nakahashi/markit that referenced this issue Mar 17, 2023
ERROR in ./node_modules/fsevents/fsevents.node 1:0
Module parse failed: Unexpected character '�' (1:0)

yan-foto/electron-reload#71
LarrMarburger pushed a commit to LarrMarburger/privacy.sexy that referenced this issue Nov 16, 2023
Upgrade to v5.x using `vue upgrade --next`.

Update `vue.config.js` to import and use `defineConfig`, because it
provides type safety and created by Vue CLI 5 as default.

Vue CLI 5.x upgrades from webpack 4 to 5. It causes some issues that this
commit attemps to fix:

1. Fail due to webpack resolving of Ace.
   Third-party dependency (code editor) Ace uses legacy `file-loader`
   for webpack resolving. It's not supported in webpack 5. So change it
   with manual imports.
   Refs: ajaxorg/ace-builds#211, ajaxorg/ace-builds#221.

2. Wehpack drops polyfilling node core modules (`path`, `fs`, etc.).
   Webpack does not polyfill those modules by default anymore. This is
   good because they did not need browser polyfilling as they are
   used in desktop version only and resolved already by Electron.
   To resolve errors (using webpack recommendations):
    - Add typeof check around `process` variable.
    - Tell webpack explicitly to ignore used node modules.

3. Fail due to legacy dependency of vue-cli-plugin-electron-builder.
   This plugin is used for electron builds and development. It still
   uses webpack 4 that leads to failed builds.
   Downgrading `ts-loader` to latest version which has support for
   `loader-utils` solves the problem (TypeStrong/ts-loader#1288).
   Related issue: nklayman/vue-cli-plugin-electron-builder#1625

4. Compilation fails due to webpack loading of `fsevents` on macOS.
   This happens only when running `vue-cli-service test:unit` command
   (used in integration tests and unit tests). Other builds work fine.
   Refs: yan-foto/electron-reload#71,
     nklayman/vue-cli-plugin-electron-builder#712,
     nklayman/vue-cli-plugin-electron-builder#1333
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

9 participants