0

error:sh: 1: nodemon: not found

packages:

{
  "name": "shorturlproxy",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "keywords": [],
  "description": "",
  "devDependencies": {
    "nodemon": "^2.0.15"
  }

Do you know what I do wrong?

Mediator
  • 14,387
  • 34
  • 108
  • 180
  • Heroku strips development dependencies after the build (read [the docs](https://devcenter.heroku.com/articles/nodejs-support#package-installation)). Why use nodemon in production anyway? – jonrsharpe Jan 24 '22 at 19:18
  • I'm out of comment upvotes for the day, but jonrsharpe is correct: you shouldn't be using `nodemon` on Heroku in the first place. If you need to build your code (e.g. to compile TypeScript or minify CSS or build a production Vue.js release or something), add a build script that does that and then just use `node` in your start script. If you want to use `nodemon` for local development call it something else. A dev script is common for this. – Chris Jan 24 '22 at 19:48
  • Does this answer your question? [Heroku failing to start my node app because its trying to do it with nodemon](https://stackoverflow.com/questions/22618930/heroku-failing-to-start-my-node-app-because-its-trying-to-do-it-with-nodemon) – Chris Jan 24 '22 at 19:50

1 Answers1

0

The simple way is call the (local) "nodemon" with relative path, so replace the "start" value:

"scripts": {
  "start": "./node_modules/.bin/nodemon index.js",
  "test": "echo \"Error: no test specified\" && exit 1"
},

Also there is a way to install it globally (npm i -g nodemon) before running the server, but I'm not sure this will work on Heroku

boolfalse
  • 1,431
  • 2
  • 11
  • 10
  • That won't work on Heroku. – Chris Jan 24 '22 at 19:47
  • actually I also not recommend to use nodemon on heroku.. I think he just want to run the server as a listener.. then he can use pm2, forever or something like that.. but that was just simple way.. anyway if you sure about that, then thanks for info – boolfalse Jan 24 '22 at 19:52
  • also, please can you say the reason, why it shouldn't work – boolfalse Jan 24 '22 at 19:54
  • I'm _pretty_ sure about it since by default [Heroku strips `devDependencies` from the application slug after building](https://devcenter.heroku.com/articles/nodejs-support#package-installation). But I haven't actually tested it. – Chris Jan 24 '22 at 19:54
  • interesting.. thanks – boolfalse Jan 24 '22 at 19:55