Volodymyr Bezuglyy
Volodymyr Bezuglyy

Reputation: 16795

Cannot start JS application packed by Electron. Uncaught TypeError: require.nodeRequire is not a function

I packed our JS web-application by Electron.
There is following error when I trying to start this packed application:

text.js: Uncaught TypeError: require.nodeRequire is not a function

There is no function nodeRequire in our version of RequireJS.
As I understand version of RequireJSfor NodeJS is different from from version of RequireJSfor browsers.
What should I do to fix this problem?
Should I use in our web-application other version of RequireJS?
Or is it possible to configure Electron to avoid this error?

Upvotes: 0

Views: 605

Answers (3)

Pogrindis
Pogrindis

Reputation: 8091

Its how require.js is looking to load versus; how electron wants to load the webcontent. Mainly the masterconfig enviornment is not defined and so uses the problematic nodeRequire.

Following up on @Jose Rego's answer, which guided me in the right direction.

Provided you have the nodeIntegration set to false, you also need to ensure that the content is being loaded into the browser as an URL:

// Creazione della finestra del browser.
mainWindow = new BrowserWindow({ width: 800, height: 600, 
                                 webPreferences: { nodeIntegration: false } });

Then when you are loading your content, specify it to behave as a URL:

mainWindow.loadURL(
url.format({
  pathname: path.join(__dirname, `[STATIC_CONTENT_PATH]`),
  protocol: "file:",
  slashes: true
 })
);

Upvotes: 0

Jose Rego
Jose Rego

Reputation: 450

Electron provides a config that worked for me.

// In the main process
var mainWindow = new BrowserWindow({
  webPreferences: { nodeIntegration: false }
});

Upvotes: 1

Jens Habegger
Jens Habegger

Reputation: 5446

The problem is not actually in Electron or RequireJS, but in the text.js loader. Do you actually need that loader?

Upvotes: 0

Related Questions