Switch to electron using an existing require config... how to avoid conflict with require("remote")?



My project is already using require to manage all the module.

    baseUrl: 'js',
    paths: {
        root: '../',
        text: 'lib/text'

and a typical file looks like it :

define(function (require) {
    'use strict';

    var module1 = require('path/to/module1');
    var module2 = require('path to module2');
    // code

    return something;

now, i’m trying to use require("remote") for example, but it’s equivalent to writing require("js/remote") which require cannot find (this makes sense!)


what are my options ? convert my existing code to using the module / export ES6 thing (I’m not familiar with it) or is there a way to tell require to find “remote” and its friends (web-contents, etc.) elsewhere ?


Electron is based off of Chromium and Node.js. The require mechanism that Electron uses is from Node.js. So if you want to use any Node modules in your project, you may want to consider converting to using the in-built require mechanism.


Here is the answer I got on slack

You can do something like this:

<script type="text/javascript">
    window.requireNode = window.require;
    window.require = undefined;

this works perfectly for my case. I then use window.requireNode(“remote”) and this is fine