{"id":750,"hash":"af7d7587752a5c3e9f0041ff26bb3116b3d81df849db45c82ab1c680ee0d4d98","pattern":"Uncaught Error: Cannot find module &#39;jquery&#39;","full_message":"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.\n\nHere is the structure of my app in Atom Editor:\n\ni.e it is having following parts:\n\nmain.js  \npackage.json\nnodemodules>jquery (to load jquery)\n\nSource code:\n\nmain.js:\n\n   'use strict';\n\n    var app = require('app');\n\n    app.on('ready', function() {\n      var BrowserWindow = require('browser-window');\n\n      var win = \n      new BrowserWindow({ width: 800, height: 600, show: false, \n               'node-integration':true });\n      win.on('closed', function() {\n        win = null;\n      });\n\n      win.loadUrl('http://mydummysite/index.html ');\n      win.show();\n    });\n\npackage.json:\n\n{\n  \"name\": \"my-mac-app\",\n  \"version\": \"5.2.0\",\n  \"description\": \"My Mac Desktop App\",\n  \"main\": \"main.js\",\n  \"scripts\": {\n    \"start\": \"electron .\"\n  },\n  \"author\": \"Me\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"jquery\": \"^2.1.4\"\n  }\n}\n\nExternal page - http://mydummysite/index.html page code:\n\n<!DOCTYPE html>\n<html>\n  <head>\n  </head>\n  <body>\n    <h1>Hello World!</h1>\n\n  </body>\n<script>\n\n   var jqr=require('jquery');\n\n</script>\n</html>\n\nWhen I run the above app (by dragging the application folder to Electron) the external page (http://mydummysite/index.html) loads in Electron shell\nbut with the error \n\n  Uncaught Error: Cannot find module 'jquery'\n\nCan you help me finding the cause of this issue?\n\nAs 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. \n\nNote: 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\"). \n\nDid I add external module (jquery) in correct way in Electron?\n\nAm I missing some dependency in package.json?\n\nWhat I have already tried:\n\nnpm cache clean, npm install jquery (to my app folder) \nnpm install --save jquery\nnpm install jquery -g\nnpm rebuild\nsudo npm install jquery -g\nsudo npm install jquery\nexport NODE_PATH=/usr/local/lib/node_modules\n\nHere is the screenshot of the location from where the error is thrown in module.js\n\nCan someone suggest why require(\"ipc\") is working and require(\"jquery\") not? \n\nMy goal is to use jQuery with electron app with node-integration true.","ecosystem":"npm","package_name":"jquery","package_version":null,"solution":"tl;dr\n\nIn 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.\n\nUpdate:\n\nThe answer to the question\n\nwhy require(\"ipc\") is working and require(\"jquery\") not?\n\nis to be found in this issue, stating that system/user modules should not be included in the global path of the module\n\nsince they could contain modules not shipped with the app and possibly compiled with the wrong v8 headers.\n\nAnd if you take a look at electron's source you can see that internal modules are added to the module.globalPaths:\n\n# Add common/api/lib to module search paths.\nglobalPaths.push path.resolve(__dirname, '..', 'api', 'lib')\n\nthats why you have access to ipc, app, etc. but not the modules that you have installed globally using npm install -g.\n\nI 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:\n\nexport NODE_PATH=/PATH/TO/APP/node_modules\nelectron /PATH/TO/APP\n\nWhen exporting NODE_PATH make sure that you provide an absolute path.\n\n**Update 2:**\nThe answer to the comment:\n\nI get jQuery not found errors\n\nIs 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:\n\n<script src=\"https://code.jquery.com/jquery-2.1.4.min.js\"></script>\n\nWhat 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)\n\nWhen 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.\n\nNow 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:\n\n<script>\n  window.jQuery = window.$ = require('jquery');\n</script>\n\nI have written an article that explains the combination of Node + jQuery.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/32265449/uncaught-error-cannot-find-module-jquery","votes":62,"created_at":"2026-04-19T04:51:36.211012+00:00","updated_at":"2026-04-19T04:51:36.211012+00:00"}