Closed xxczaki closed 3 years ago
Are you using one of the examples? Is there a repo that I can clone?
@lacymorrow The app is based on the with-typescript
example. Here is the repo: https://github.com/parsify-dev/desktop
@lacymorrow After I remove import {ipcRenderer} from 'electron';
everything works fine. Doing:
import electron from 'electron';
// Prevent SSR webpacking
const ipcRenderer = electron.ipcRenderer || false;
doesn't fix this issue.
@xxczaki Can you try something like
import electron, { ipcRenderer } from 'electron'
if ( ipcRenderer ) {
// ipcRenderer.on( key, fn )
}
@lacymorrow Unfortunately this does not fix the issue :cry:
Are you able to build the with typescript
example properly?
@lacymorrow Sorry for the late reply. Yes, I'm able to build it.
After removing all instances of ipcRenderer
from the renderer
directory, build finishes successfully.
Now the build succeeds, but electron is removed completely from it (so I can't use ipcRenderer
) :cry:
Solved it. I modified the next.config.js
:
webpack: (config, {isServer}) => {
if (!isServer) {
config.module.rules.push({
test: /electron/,
use: "null-loader"
})
}
return Object.assign(config, {target: 'electron-renderer'});
},
Inspiration: https://github.com/zeit/next.js/issues/2069#issuecomment-593847441
That way, I make sure electron
won't get bundled with the client. I don't know why it was doing so in my case.
Is there an up-to-date repo I can take a look at? I'd like to get these imports figured out for folks in the future.
Glad you got a workaround in place!
I dug even more into this issue and I finally found a workaround, which makes the build succeed and also doesn't break the ipc communication:
// Instead of:
import {ipcRenderer} from 'electron';
// Do:
const {ipcRenderer} = eval('require(\'electron\')');
This was also inspired by one of the comments in Next.js' repo. This is just a workaround - as we all know the usage of eval
is not really recommended, but it works.
@lacymorrow the repo itself is private, but I will try to make a separate repository for reproduction tomorrow :smile:
Any updates @xxczaki ?
Sorry for a late reply. Here is the repo: https://github.com/xxczaki/nextron-ipc-bug/
It looks like this issue does no longer occur with Nextron v6 and higher.
Description
When I try to build the app, a build error occurs:
Debug information
5.14.4
9.3.1
8.1.1
16.13.0
What I already tried
.next
andnode_modules
and reinstalling dependencies.next
to9.3.0
const plugins = [ ['babel-plugin-styled-components', { ssr: true, pure: true }] ];
module.exports = {presets, plugins};
Nothing worked :cry: