Richienb/node-polyfill-webpack-plugin

process.arch and process.platform are missing from polyfill

Closed this issue · 7 comments

Hi. Please take a look at zeromq/zeromq.js#676

So the proximate cause is that the polyfill is not providing process.arch and process.platform which is causing zeromq to barf when packed with webpack.

The process/browser package has not been updated since 2016 or so.

What do you think should be done in this case?

Thank you.

What do you think should be done in this case?

I think we should maintain our own fork of the process polyfill that adds these features.

I know it's not "secure" but it really would simplify things If I am able to inject 'fs' and 'process' directly into the renderer process on electron-forge+webpack.

This horrendous going back and forth via ipcMain and ipcRenderer is so fragile and difficult to get right...
Even worse, None of the examples on https://www.electronjs.org/docs/latest/tutorial/ipc actually work out of the box. :-(

Do you have any advice on how I might go about writing such a polyfill? (please mind I am n00b w.r.t. webpack)

I know it's not "secure" but it really would simplify things If I am able to inject 'fs' and 'process' directly into the renderer process on electron-forge+webpack.

@devzzzero In an Electron app, you can just call the Node.js APIs directly, no polyfill needed.

I know it's not "secure" but it really would simplify things If I am able to inject 'fs' and 'process' directly into the renderer process on electron-forge+webpack.

@devzzzero In an Electron app, you can just call the Node.js APIs directly, no polyfill needed.

Yes. Thank you. I tried setting contextIsolation:false It doesn't seem to work any more. :-( At least, not on the renderer side...

I tried setting contextIsolation:false It doesn't seem to work any more.

Did you also try set nodeIntegration: true?

If it doesn't work, try using a preload script, which can even make functions calling Node.js APIs available in the renderer.

Did you also try set nodeIntegration: true?

I tried all of the following at once. but I had no luck trying to get zmq to load up on the renderer side.

  const mainWindow = new BrowserWindow({
    height: 1200,
    width: 1600,
    backgroundColor: "#202020",
    webPreferences: {
      sandbox: false,
      contextIsolation:false,
      nodeIntegration: true, // <--- flag
      nodeIntegrationInWorker: true, // <---  for web workers
      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
    },
  });

I think this is a combination of electron documentation bit rot combined with the fact that the last version of electron I worked with was 8.5! It was an entirely different particle way back then. :-)

If it doesn't work, try using a preload script, which can even make functions calling Node.js APIs available in the renderer.

Interesting! I'll take a look . Thank you! @Richienb !!!