【问题标题】:Fixing Heroku exited with status 1, error code H10修复 Heroku 以状态 1 退出,错误代码 H10
【发布时间】:2022-01-18 08:27:36
【问题描述】:

我尝试了各种解决方案;使用 GitHub 作为部署方式,安装 NPM 包 serve,强制清理缓存,重新安装 node_modules & package-lock.json,甚至将项目从 NPM 切换到 Yarn。我仍然收到以下错误。

错误日志:

2022-01-17T16:20:29.660758+00:00 heroku[web.1]:进程退出 状态 1 2022-01-17T16:20:29.752386+00:00 heroku[web.1]:状态已更改 从开始到崩溃 2022-01-17T16:20:30.611091+00:00 heroku[路由器]: at=error code=H10 desc="App crashed" 方法=GET path="/" 主机=ip-tracker-app.herokuapp.com request_id=a46f3082-43fd-45e9-a049-d1076cad194f fwd="2.125.111.225" dyno=连接=服务=状态=503字节=协议=https 2022-01-17T16:20:31.020509+00:00 heroku[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET path="/favicon.ico" 主机=ip-tracker-app.herokuapp.com request_id=c01ac432-ae1c-4994-9fa0-b211a8f00391 fwd="2.125.111.225" dyno=连接=服务=状态=503字节=协议=https

我的 Package.json 文件:

{
  "name": "ip-address-tracker",
  "version": "1.0.0",
  "description": "*Removed for question*",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "start": "node server.js",
    "test": "jest --coverage",
    "devStart": "nodemon server.js"
  },
  "jest": {
    "transform": {
      "^.+\\.[t|j]sx?$": "babel-jest"
    }
  },
  "repository": {
    "type": "git",
    "url": "*Removed for question*"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "*Removed for question*",
  },
  "homepage": "*Removed for question*",
  "dependencies": {
    "dotenv": "^10.0.0",
    "express": "^4.17.2",
    "jest": "^27.4.7",
    "serve": "^13.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.16.7",
    "@babel/preset-env": "^7.16.8",
    "babel-jest": "^27.4.6",
    "nodemon": "^2.0.15",
    "regenerator-runtime": "^0.13.9"
  }
}

我的 server.js 文件:

const express = require('express');
const app = express();
const dotenv = require('dotenv');
const result = dotenv.config();

if (result.error) {
    throw result.error;
}

const PORT = process.env.PORT || 3000;

app.use(express.static('public'));

app.listen(PORT, () => {
    console.log(`App is listening on ${PORT}.`);
});

我添加了以下 Procfile:

web: npm start

【问题讨论】:

    标签: javascript node.js heroku


    【解决方案1】:

    如果你想提供像 dist 这样的 html 文件,我在你的服务器上看到了一个问题,试试这个

    app.use('/', serveStatic(path.join(__dirname, '/public')))
    

    如果目的是传递图像

    app.use(express.static(path.join(__dirname,'public')))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-28
      • 2021-03-23
      • 2017-02-11
      • 2021-08-13
      • 2017-12-13
      • 2015-05-04
      • 1970-01-01
      • 2020-10-18
      相关资源
      最近更新 更多