【问题标题】:Not able to deploy NodeJS App in Heroku无法在 Heroku 中部署 NodeJS 应用程序
【发布时间】:2016-12-16 07:21:08
【问题描述】:

我使用 JetBrain Webstrom 创建了一个 NodeJS 应用程序,现在我想将它部署到 heroku。

This image contains my app directory

我应该删除 node_modules 来部署应用程序吗? 还是我应该在 package.json 下添加任何“引擎”部分? 我应该怎么做才能在 heroku 中正确部署我的应用程序。

我应用的 package.json:

{
  "name": "form",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.15.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "ejs": "~2.5.2",
    "express": "~4.14.0",
    "morgan": "~1.7.0",
    "serve-favicon": "~2.3.0"
  }
}

在推送应用时记录:

C:\Users\Adhik\formgp>git push heroku master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 585 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 3 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote:  !     No default language could be detected for this app.
remote:                         HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote:                         See https://devcenter.heroku.com/articles/buildpacks
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to serene-bayou-91098.
remote:
To https://git.heroku.com/serene-bayou-91098.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/serene-bayou-91098.git'

【问题讨论】:

标签: node.js git heroku github heroku-toolbelt


【解决方案1】:

尝试将其添加到您的 package.json:

  "engines": {
    "node": "whatever_version_you_want"
  }

您不需要安装/删除 node_modules,Heroku 应该为您完成。

【讨论】:

  • node_modules 应该在 .gitignore 中,不过。
【解决方案2】:

您的 package.json 中似乎缺少引擎:

"engines": {
    "node": "6.7.0",
    "npm": "3.10.3"
  }

部署 Procfile 也很有帮助:

web: node ./bin/www

您确定要部署整个文件夹吗?检查您的日志:

Counting objects: 3, done.

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多