Using loadUrl and angular module


Hi everyone.

I’m trying to use loadUrl in an electron app. And the site which the url points to is an node-app that requires angular.

So when i do this in main.js: mainWindow.loadURL(‘’);
i get the following error in the console: module.js:442 Uncaught Error: Cannot find module ‘angular’

i have installed and added angular to package.json like this:

“dependencies”: {
“angular”: “^1.2.31”,
“ngprogress-lite”: “^1.0.8”

If i set a breakpoint in module.js on line 442 i can see that electron looks for the module angular in “/usr/local/lib/node_modules/electron-prebuilt/dist/” instead of my node_modules folder where i have angular.

Am i missing something?


Your mainWindow is calling an external, served page, so anything you do on the app side won’t make a difference. I’d assume it’s related to Angular in mainWindow is seeing that it’s in a Node environment, and trying to use that, rather than applying global objects to the window object. You can turn off the Node integration by passing {webPreferences:{nodeIntegration:false}} to the new BrowserWindow call.


Thanks caffiend!
That worked like a charm.

For others running in to this problem, this is how the browser window is instantiated with webPreferences. (you can leave the titlebarStyle out):

mainWindow = new BrowserWindow({titleBarStyle: ‘hidden’, webPreferences:{nodeIntegration:false} })