As a rule, in the Electron application you can require node modules from both the main process and the visualization process:
var myModule = require('my-module');
However, this does not work if the page was loaded via HTTP, and not from the local file system. In other words, if I open the window as follows:
win.loadURL(`file://${__dirname}/index.html`);
I can require a node module without problems. But if I open the window like this instead:
win.loadURL(`http:`);
I can no longer require node modules inside my web page - I get Uncaught Error: Cannot find module 'my-module' in the web page console. Is there a way to use node modules on an Electron page that has been transmitted via HTTP?
A small context: my company is creating an application that should be hosted as a web application and inside the Electron shell. To make this easier and more consistent in both environments, the Electron application launches the local web server and opens the application hosted at http://localhost:1234 . Now I need the ability to add electron-spell-check-provider checker / electron-spell-check-provider checker applications to the application using electron-spell-check-provider . This module needs to be imported and initialized inside the rendering process, so I'm trying to require('electron-spell-check-provider') on my web page, but this is not with Cannot find module error.
source share