Deploying node app on heroku firing errors related to nodemon

廉价感情. 提交于 2019-12-24 11:22:46

问题


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?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/53806768/deploying-node-app-on-heroku-firing-errors-related-to-nodemon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!