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.
Related
I want to run the npm command 'npm audit fix --force', because I already ran 'npm audit fix' and there are still vulnerabilities, is there a way I can somehow fix all the vulnerabilities without breaking my program, I tried running the command in a cloned file to see what damage it would cause, and you guessed it, it broke.
Is there a way I can somehow modify the package.json and package-lock.json to fix this?
Here is my package (making a login and registration system via mongodb)
{
"name": "passport-local-register-login",
"version": "2.0.0",
"description": "Node.js authentication with Passport",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"ejs": "^2.6.1",
"express": "^4.16.4",
"express-ejs-layouts": "^2.5.0",
"express-session": "^1.15.6",
"mongoose": "^5.7.5",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
I have a project that is using express for the backend API. The project is working on my local machine but when I try to deploy it on a linux VM I get the error "Cannot find module 'Express'".
The steps I took to produce this error were cloning and cding into the repo, and running npm install. express is listed as a dependency in the package.json file. I tried explicitly running npm install express and npm install -g express and both said that they added and/or updated packages and did not return any errors. I also looked in the node_modules folder and there is an express folder there as well.
My package.json:
{
"name": "user-backend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-start": "nodemon server.js",
"nvm-start": "nvm use 8.11.3",
"postnvm-start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"faker": "^4.1.0",
"helmet": "^3.12.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.2",
"morgan": "^1.9.0",
"request": "^2.88.0",
"slugify": "^1.3.1",
"validator": "^10.4.0"
},
"devDependencies": {
"nodemon": "^1.18.1"
}
}
Any help would be greatly appreciated. Thank you
This ended up being a simple syntax error in my import ("Express" vs "express")
I created a Express application by Express test and then I npm installthe package in test directory,but when I use npm start,my project can not run in my browser.Just like that:
This situation kept for a long time and I don't know how to deal with it.
My package.json is:
{
"name": "test",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jade": "~1.11.0",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2"
}
}
Can anyone help me ?
I need some help, i'm trying to add mongoose to my openshift v3 env but can't find how.
already try to use package.json.
Edit :
deploy log
package.json
{
"name": "nodejs-ex",
"version": "0.0.1",
"description": "projet",
"main": "server.js",
"dependencies": {
"body-parser": "^1.17.2",
"chai": "^3.5.0",
"chai-http": "^2.0.1",
"ejs": "^2.4.1",
"express": "^4.13.4",
"mocha": "^2.4.5",
"mongodb": "^2.1.16",
"mongoose": "^4.10.3",
"morgan": "^1.7.0",
"object-assign": "4.1.0"
},
"engine": {
"node": "*",
"npm": "*"
},
"scripts": {
"start": "node server.js",
"test": "IP=0.0.0.0 PORT=3030 mocha --timeout 5000 tests/*_test.js"
},
Thanks
I'm getting the error heroku cannot find module 'Sequelize' when the server runs npm start on index.js file. When I run it locally by command heroku local it works fine. What I don't understand is that there is no module called 'Sequelize' in my project. It's called in lower case sequelize. Here's my package.json
{
"name": "anonbay",
"version": "1.0.0",
"description": "social network app",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "saud",
"license": "ISC",
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.16.0",
"express": "^4.14.0",
"express-graphql": "^0.6.3",
"express-session": "^1.15.3",
"graphql": "^0.9.1",
"graphql-subscriptions": "^0.3.1",
"lodash": "^4.17.4",
"mongoose": "^4.7.7",
"pg": "^6.1.2",
"pg-hstore": "^2.3.2",
"sequelize": "^3.30.4",
"subscriptions-transport-ws": "^0.6.0"
}
}
My bad I was importing 'Sequelize' with uppercase. It works locally but it seems heroku is case sensitive. Changed it to 'sequelize' and it worked