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:
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
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
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