How to use js library in electron app #558

Closed
opened 2026-01-29 16:42:55 +00:00 by claunia · 1 comment
Owner

Originally created by @gpgpublickey on GitHub (Aug 19, 2020).

Hello guys could you please explain how to achieve this?

I'm adding two js files from cdn in my _Host.cshtml, but at time to use the methods exposed by this libraries I have this result:
image

The library that I'm trying to use is called toastr (https://github.com/CodeSeven/toastr). but I can't find the way to be able to use it in the electron application.

This is the < head > of my _Host.cshtml:
image

Is weird because if I open localhost + port in my real web browser works fine but from electron, it is not working

Originally created by @gpgpublickey on GitHub (Aug 19, 2020). Hello guys could you please explain how to achieve this? I'm adding two js files from cdn in my _Host.cshtml, but at time to use the methods exposed by this libraries I have this result: ![image](https://user-images.githubusercontent.com/7245667/90579237-cd5fa780-e19b-11ea-95d2-1bbc640cee86.png) The library that I'm trying to use is called toastr (https://github.com/CodeSeven/toastr). but I can't find the way to be able to use it in the electron application. This is the < head > of my _Host.cshtml: ![image](https://user-images.githubusercontent.com/7245667/90579318-04ce5400-e19c-11ea-8d8b-680c43ab4f54.png) Is weird because if I open localhost + port in my real web browser works fine but from electron, it is not working
claunia added the bug label 2026-01-29 16:42:55 +00:00
Author
Owner

@gpgpublickey commented on GitHub (Aug 22, 2020):

To solve this:

electron FAQ answer :

http://electron.atom.io/docs/faq/

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>
@gpgpublickey commented on GitHub (Aug 22, 2020): To solve this: electron FAQ answer : http://electron.atom.io/docs/faq/ 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>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#558