require is not defined when putting ipcRenderer.on in /src/renderer.ts #5
Replies: 10 comments
-
Hello @raphael10-collab Its good to know this boilerplate been a good starting point for you. For the issues you mentioned regarding:
Can you try the same process with following webPreferences: {
nodeIntegration: true, // Changed
enableRemoteModule: false,
contextIsolation: false, // Changed
nodeIntegrationInWorker: false,
nodeIntegrationInSubFrames: false,
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
}, In this boilerplate |
Beta Was this translation helpful? Give feedback.
-
With
it doesn't give require is not defined when inserting in renderer.ts:
So.. the hurdle now changes:
and being able in the same time to import ipcRenderer in renderer.ts? |
Beta Was this translation helpful? Give feedback.
-
How about using/importing
For the communication between both // Main process
ipcMain.handle('my-invokable-ipc', async (event, ...args) => {
const result = await somePromise(...args)
return result
})
// Renderer process
async () => {
const result = await ipcRenderer.invoke('my-invokable-ipc', arg1, arg2)
// ...
} |
Beta Was this translation helpful? Give feedback.
-
When importing ipcRenderer in preload.ts instead of renderer.ts:
It seems that renderer.ts doesn't recognize ipcRenderer :
|
Beta Was this translation helpful? Give feedback.
-
I defined the 'electron-renderer' as target in /tools/webpack/webpack.renderer.js :
But still get the error :
I tried to import ipcRenderer in preload.js as follows:
But I get
Following these indications: electron/electron#9920 (comment)
But I get the same error in renderer.ts:
|
Beta Was this translation helpful? Give feedback.
-
Just tried using following in // preload.ts
import { ipcRenderer } from 'electron';
console.log(ipcRenderer);
Instead of exposing |
Beta Was this translation helpful? Give feedback.
-
I just followed the example in https://www.electronjs.org/docs/api/context-bridge#contextbridge preload.js : import { ipcRenderer, contextBridge } from 'electron';
renderer.js :
Error:
|
Beta Was this translation helpful? Give feedback.
-
Following is compilation error by typescript compiler because of // index.d.ts
declare interface Window {
electron: {
doThing(): void
}
} |
Beta Was this translation helpful? Give feedback.
-
Yes. Now it seems working with: in main.js
preload.js :
index.d.ts :
and renderer.ts :
Thank you very much @codesbiome !!!! |
Beta Was this translation helpful? Give feedback.
-
Your welcome @raphael10-collab This issue will be converted into |
Beta Was this translation helpful? Give feedback.
-
Hi!!
Thank you for this excellent electron-react-webpack-typescript starting point.
I'm trying to start from it to transpose within it this other simple example of two windows communication:https://github.com/kahlil/electron-communication-example
But I'm encountering this hurdle: when inserting into /src/renderer.ts these lines:
I get this error:
This is the entire /src/renderer.ts file:
Based on what I found here: // https://stackoverflow.com/questions/44008674/how-to-import-the-electron-ipcrenderer-in-a-react-webpack-2-setup , I've also put in tools/webpack/webpack.plugins.js :
I tried to import electron in renderer.ts as a window component:
But got:
It must be something related to the interaction among electron, react and webpack, but I didn' find any solution yet.
Would you be so kind in helping me?
Beta Was this translation helpful? Give feedback.
All reactions