I have an application that's running fine locally, but cannot run when deployed. The message is
Error: Cannot find module 'jsonwebtoken'
even though I have it in "dependencies" in my package.json (not devdependency)
I tried "heroku run bash" and verified that jsonwebtoken exists in the node_modules folder.
Finally I tried "heroku local web" and it works fine.
But for some reason it never works when deployed.
This is the start of the file that needs jsonwebtoken
var mongoose = require('mongoose');
var crypto = require('crypto');
console.log('check1');
var jwt = require('jsonwebtoken');
console.log('check2');
It gets to "check1" but not "check2"
This is my package.json
{
"name": "loc8r",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"engines": {
"node": "~0.10.13",
"npm": "~1.3.2"
},
"dependencies": {
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"debug": "^2.0.0",
"dotenv": "^4.0.0",
"express": "~4.9.0",
"express-jwt": "^5.3.0",
"jade": "~1.6.0",
"jsonwebtoken": "^8.1.0",
"mongoose": "^4.13.5",
"morgan": "~1.3.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"request": "~2.51.0",
"serve-favicon": "~2.1.3",
"uglify-js": "~2.4.15"
},
"description": "myapp",
"main": "app.js",
"devDependencies": {},
"keywords": [],
"author": "",
"license": "ISC"
}
Can someone please help me figure out what's going on?
The node version you are using on Heroku is too old judging from the package.json of jsonwebtoken. I would suggest upgrading to the latest version.
I'm pretty sure it works locally for you because you are running a newer version than 0.10.X on your own computer.