How to access require in dojo/require.js apps?


#1

currently i carry it by tracking it as variable in window[‘eRequire’], done in the renderer code.

however, the latest electron detector is “window.process.*” but i can’t find Electron’s require anywhere in there.

so what would be the safe path to get require :slight_smile: ?

thanks a lot.

ps: these things happen if your app needs to run outside of electron


#2

It’s in the FAQ: https://github.com/electron/electron/blob/master/docs/faq/electron-faq.md#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron

I can not use jQuery/RequireJS/Meteor/AngularJS in Electron.

Due to the Node.js integration of Electron, there are some extra symbols
inserted into the DOM like module, exports, require. This causes problems
for some libraries since they want to insert the symbols with the same names.

To solve this, you can turn off node integration in Electron:

// In the main process.
let win = new BrowserWindow({
  webPreferences: {
    nodeIntegration: false
  }
});

But if you want to keep the abilities of using Node.js and Electron APIs, you
have to rename the symbols in the page before including other libraries:

<head>
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<script type="text/javascript" src="jquery.js"></script>
</head>

#3

thanks, but no, dont want to disable anything


#4

You wouldn’t be disabling it, just holding onto it under a different name. Although, I suppose that’s what you’re referring to in your first post?

Anyhow, you need to access Electron’s require before calling any other scripts that might override it.


#5

ok, thanks. i understand. so at the end i will have to trace it just as described in my first post, or something similar as described later.

i just hoped, Electron keeps somewhere else its require pointer but ok, can live with that.

g