Quasar: Uncaught TypeError: fs.existsSync is not a function

Created on 5 Jul 2019  路  6Comments  路  Source: quasarframework/quasar

Describe the bug
I am trying to use the Electron ipcRenderer in a boot file. This provides some oAuth functionality to my app.

To Reproduce
Steps to reproduce the behavior:

  1. Create a boot file, e.g. oauth/index.js
  2. Add: const { ipcRenderer } = require('electron');
  3. Call ipcRenderer.send('exampleEvent', 'test-message');

I am wrapping this call to ipcRenderer in Quasar's Platform Detection like so:

if (Platform.is.electron) {
    ipcRenderer.send('exampleEvent', 'test-message');
}

Expected behavior
This works fine when building Electron or Electron dev, but it is causing an error when building SPA or SPA dev.

Uncaught TypeError: fs.existsSync is not a function

Related to this issue:
https://github.com/electron/electron/issues/7300

Platform (please complete the following information):
OS: Windows
Node: 10.15.3
NPM: 6.4.1
Yarn: 1.10
Browsers: Chrome

bug

Most helpful comment

You will need to add some checks in yourself to only run this code on electron - it will not work outside of the electron environment (obviously as you're requiring electron).

Take a look at this link to see how: https://quasar.dev/options/platform-detection#Usage

All 6 comments

You will need to add some checks in yourself to only run this code on electron - it will not work outside of the electron environment (obviously as you're requiring electron).

Take a look at this link to see how: https://quasar.dev/options/platform-detection#Usage

Thanks,. I am already using Quasar's Platform detection to ensure that this code is only run on Electron. Please see my updated steps to reproduce above.

Configure your boot file to be included only for Electron mode.

// quasar.conf.js
boot: [
  ctx.mode.electron ? 'some-file' : ''
]

Cheers. I found that in the docs. I might have to rethink the implementation of my oauth system, otherwise I will be duplicating the code into an Electron only oauth Boot File and an SPA only oauth Boot file.

And your const { ipcRenderer } = require('electron');? Is that also contained in the Platform detection?

How would one require a file based on Platform detection? The only way I can think of is the way Razvan has suggested and perform platform detection in quasar.conf.

I have decided to go with two separate oAuth Boot files and move common functionality outside. This works fine my current needs and it won't be too difficult to manage.

Are we sure this isn't a conflict with Webpack vs Electron's require methods? It's covered in that electron issue that I linked

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xereda picture xereda  路  3Comments

jean-moldovan picture jean-moldovan  路  3Comments

victorborgaco picture victorborgaco  路  3Comments

wc-matteo picture wc-matteo  路  3Comments

danikane picture danikane  路  3Comments