Blocker for electron/fiddle#1114
For migrating the Node APIs from the renderer process to the main process, the IPCRenderer
API is to be moved to preload scripts and then exposed in the renderer process via the contextBridge
API.
The below diagram explains it better -
The above image shows the expected architecture wherein nodeIntegrationInWorker
is to be set false before proceeding ahead. However, nodeIntegrationInWorker
is required by us for the monao web workers to function properly in the production build of fiddle.
The error can be confirmed with the logs -
Uncaught ReferenceError: require is not defined
at ts.worker.js:2:2658562
at ts.worker.js:2:4313768
3index.js:2 Uncaught Error: Unexpected usage
Error: Unexpected usage
at at.loadForeignModule (index.js:2:3849383)
at index.js:2:3858113
at index.js:2:1626096
at i (index.js:2:968071)
3index.js:2 Uncaught (in promise) Error: Unexpected usage
at at.loadForeignModule (index.js:2:3849383)
at index.js:2:3858113
The issue is because html-webpack-plugin doesn't support the __dirname
API, due to which webpack-asset-relocator-loader is being monkey patched in forge for it to function properly.
This can be confirmed by modifying the monaco-editor getWorkerUrl to point it to compiled web workers. By doing so the fiddle production build throws an error saying - __dirname is not defined
.
For a more detailed reasoning - corresponding slack conversation link.
jantimon/html-webpack-plugin#1650 was created to add the support for __dirname
but it was closed by a bot for being stale. Probably, it can be re-opened and work upon again.
If by any chance the upstream repository is reluctant to add these changes we can probably maintain a fork of html-webpack-plugin and webpack-asset-relocator-loader to modify electron forge in order to avoid monkey patching (However, this will cost us time and extra efforts to maintain them)
Unfortunately, the offical summer period is about to be over. However, I will still be unofficially working to resolve this bug and eventually proceed with the pr i.e to migrate all the Node APIs in renderer process to main process. (Apologies, if I wasn't able to complete this task before specified time)