Organizational Research By

Surprising Reserch Topic

uncaught error cannot find module jquery

uncaught error cannot find module jquery  using -'javascript,jquery,node.js,atom-editor,electron'

I am using Electron to make a desktop app. In my app I am loading a an external site (outside Atom app) lets say http://mydummysite/index.html page.

Here is the structure of my app in Atom Editor:

i.e it is having following parts:

nodemodules>jquery (to load jquery)

Source code:


   'use strict';

    var app = require('app');

    app.on('ready', function() {
      var BrowserWindow = require('browser-window');

      var win =
      new BrowserWindow({ width: 800, height: 600, show: false,
               'node-integration':true });
      win.on('closed', function() {
        win = null;

      win.loadUrl('http://mydummysite/index.html ');;


  "name": "my-mac-app",
  "version": "5.2.0",
  "description": "My Mac Desktop App",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  "author": "Me",
  "license": "ISC",
  "dependencies": {
    "jquery": "^2.1.4"

External page - http://mydummysite/index.html page code:

<!DOCTYPE html>
    <h1>Hello World!</h1>


   var jqr=require('jquery');


When I run the above app (by dragging the application folder to Electron) the external page (http://mydummysite/index.html) loads in Electron shell
but with the error "Uncaught Error: Cannot find module 'jquery'"

Can you help me finding the cause of this issue?

As you can see in my screenshot of directory structure I have alread installed jquery module to my folder and I did it via "npm install jquery" command.

Note: To play with "require" command in JS I tried adding "require("ipc")" in my external page http://mydummysite/index.html page and it was working so what could be the reason with require("jquery").

Did I add external module (jquery) in correct way in Electron?

Am I missing some dependency in package.json?

What I have already tried:

npm cache clean, npm install jquery (to my app folder)
npm install --save jquery
npm install jquery -g
npm rebuild
sudo npm install jquery -g
sudo npm install jquery
export NODE_PATH=/usr/local/lib/node_modules

Here is the screenshot of the location from where the error is thrown in module.js

Can someone suggest why require("ipc") is working and require("jquery") not?

My goal is to use jQuery with electron app with node-integration true.

asked Sep 21, 2015 by santosh soni
0 votes

Related Hot Questions

4 Answers

0 votes


In contrast to a normal nodejs app, where you have access to global modules (e.g. located in /usr/bin/node), electron doesn't automatically set the NODE_PATH environment variables. You have to set it manually to all the paths containing your desired modules.


The answer to the question

why require("ipc") is working and require("jquery") not?

is to be found in this issue, stating that system/user modules should not be included in the global path of the module

since they could contain modules not shipped with the app and possibly compiled with the wrong v8 headers.

And if you take a look at electron's source you can see that internal modules are added to the module.globalPaths:

# Add common/api/lib to module search paths.
globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')

thats why you have access to ipc, app, etc. but not the modules that you have installed globally using npm install -g.

I just tried it out with the latest electron-prebuilt version with a local server serving exactly the same HTML file that you provided and I think I know what the problem is: If you don't append the path to your app node_modules directory under your app root to the NODE_PATH variable it is not going to work. So you need to do something like this:

export NODE_PATH=/PATH/TO/APP/node_modules
electron /PATH/TO/APP

When exporting NODE_PATH make sure that you provide an absolute path.

Update 2:

The answer to the comment:

I get jQuery not found errors

Is to be found in this ticket. Basically if you use the jQuery's npm package or do something like the following in your HTML files inside electron:

" rel="nofollow" target="_blank">">

What you get is a factory and not the actual jQuery object attached to the global context (e.g window). As I mentioned in a previous answer (containing also jQuery's source code)

When you require jQuery inside a CommonJS or similar environment which provides module and module.exports, what you get is a factory and not the actual jQuery object.

Now to use that factory (either by importing the code from the CDN or if you have the npm module available locally) you would need something as the following:

I have written an article that explains the combination of Node + jQuery.

answered Sep 21, 2015 by yogeshplv
0 votes

I hope below link will put some light on your doubt for

why require("ipc") is working and require("jquery") not?

answered Sep 21, 2015 by dhananjayksharma
0 votes

Install jquery with npm isn't enough :

npm install --save jquery

It recovers the source files of jQuery in your project. But you have to include the script in your html file :



Hello World!

" rel="nofollow" target="_blank">">
answered Sep 21, 2015 by ankitarajoria4
0 votes

The same issue happened to me , a simple solution is to add this to your index.js file :

app.on('ready', function() {
      var mainWindow = new BrowserWindow({
        "node-integration": false
//rest of your initialization code here.

the issue is caused by node , for more information please refer to this post

Setting node-integration to false will disable node.js in the renderer process - i.e. your app can only do what a web browser will do.

answered Sep 21, 2015 by akasati02