【问题标题】:How install nodemon to heroku?如何将nodemon安装到heroku?
【发布时间】:2022-01-25 03:33:30
【问题描述】:

错误:sh:1:nodemon:未找到

包:

{
  "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"
  }

你知道我做错了什么吗?

【问题讨论】:

  • Heroku 在构建后剥离开发依赖项(阅读the docs)。为什么还要在生产环境中使用 nodemon?
  • 我今天没有评论赞成票,但 jonrsharpe 是正确的:首先你不应该在 Heroku 上使用 nodemon。如果您需要构建代码(例如编译 TypeScript 或缩小 CSS 或构建生产 Vue.js 版本或其他东西),请添加一个构建脚本,然后在您的启动脚本中使用node。如果您想使用nodemon 进行本地开发,请使用其他名称。开发脚本对此很常见。

标签: node.js heroku nodemon


【解决方案1】:

简单的方法是使用相对路径调用(本地)“nodemon”,因此替换“start”值:

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

还有一种方法可以在运行服务器之前全局安装它(npm i -g nodemon),但我不确定这是否适用于 Heroku

【讨论】:

  • 这不适用于 Heroku。
  • 实际上我也不建议在heroku上使用nodemon ..我认为他只是想将服务器作为侦听器运行..然后他可以永远使用pm2或类似的东西..但那是只是简单的方法..无论如何,如果您确定,那么感谢您提供信息
  • 另外,请你说一下原因,为什么它不应该工作
  • 相当确定它,因为默认情况下Heroku strips devDependencies from the application slug after building。但我还没有实际测试过。
  • 有趣..谢谢
猜你喜欢
  • 1970-01-01
  • 2017-09-06
  • 2020-01-27
  • 2019-11-03
  • 1970-01-01
  • 2020-01-05
  • 2017-03-06
  • 1970-01-01
  • 2021-12-08
相关资源
最近更新 更多