1

I am trying to run my node app in heroku but I am getting this error which is related to nodemon dependency.

2018-12-16T21:32:51.891208+00:00 app[web.1]: sh: 1: nodemon: not found
2018-12-16T21:32:51.895084+00:00 app[web.1]: npm ERR! file sh
2018-12-16T21:32:51.895380+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-16T21:32:51.895627+00:00 app[web.1]: npm ERR! errno ENOENT
2018-12-16T21:32:51.895865+00:00 app[web.1]: npm ERR! syscall spawn
2018-12-16T21:32:51.896987+00:00 app[web.1]: npm ERR! turktutor_backend@1.0.0 start: `nodemon --watch`
2018-12-16T21:32:51.897151+00:00 app[web.1]: npm ERR! spawn ENOENT

I have my package.json like that:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --watch"
  },
"dependencies": {
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "express-validator": "^5.3.0",
    "googleapis": "^27.0.0",
    "jsonwebtoken": "^8.4.0",
    "mongoose": "^5.3.14",
    "mongoose-unique-validator": "^2.0.2",
    "nodemailer": "^4.7.0"
  },
  "devDependencies": {
    "morgan": "^1.9.1",
    "nodemon": "^1.18.7"
  }

i tried to follow the solution in this link that requires changing "Procfile" file, but heroku says that Procfile is no longer required for Node.js apps source

I am wondering if I need to install my devDependencies in heroku server by some command!

so please any help to solve this problem?

Muho
  • 3,188
  • 23
  • 34
  • 1
    As I know you don't need nodemon for production. Better write ```start``` script like: ```node app.js``` – Vadim Dec 16 '18 at 21:51
  • make sense, but there must be a way i guess to make nodemon runs on heroku app as a development environment ! – Muho Dec 16 '18 at 21:53

2 Answers2

3

By default, heroku only installs the non dev dependencies, that's why nodemon is not found. You can define the environment variable on heroku dashboard, however I don't think it will install dev dependencies. In production you don't need nodemon, what's your idea?

Pedro Silva
  • 2,655
  • 1
  • 15
  • 24
1

i figured out that heroku runs in a production environment by default so it does not install the dev dependencies so i created two diffrent npm scripts script in my package.json like that:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js",
    "start:dev": "nodemon --watch"
},

and when i want to run the project locally i run npm run start:dev so it load index.js by nodemon, while in heroku npm start runs by default and load index.js from a normal node command.

Muho
  • 3,188
  • 23
  • 34