Wednesday, 17 May 2017

Error: Cannot find module 'jquery' on node.js on Heroku

I am trying to include jquery and jsdom to my node.js server hosted on Heroku so that I can make ajax calls using jQuery from the console (not from a web page) like $.ajax({...}).

I keep getting the following error when deploying my Node server on Heroku:

Error: Cannot find module 'jquery'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/server.js:19:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Process exited with status 1

Here is how my package.json look like:

{
  "name": "node-api",
  "main": "server.js",
  "dependencies": {
    "body-parser": "1.17.1",
    "express": "4.15.2",
    "jquery": "3.2.1",
    "jsdom": "10.1.0",
    "mongoose": "4.9.9"
  },
  "engines": {
    "node": "6.10.3"
  }
}

Here is how I include jquery in server.js:

global.jquery = require('jquery');
window.$ = window.jquery = jquery;

Any help would be much appreciated!

Thx,

JS



via user8024159

No comments:

Post a Comment