You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Strapi至Heroku时遭遇H10(应用崩溃)错误求助

Hey there, let's troubleshoot that H10 "App crashed" error you're hitting with your Strapi deployment on Heroku. This error usually means Heroku can't successfully start or connect to your app instance, so let's break down the most common fixes step by step:

1. Verify Your Port Configuration

Heroku assigns a dynamic port to your app via the PORT environment variable, so hardcoding a port like 1337 will cause Strapi to fail to bind to the correct port. Check your config/server.js file (for Strapi 3.x) to ensure it's using the environment variable:

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337), // Falls back to 1337 only if PORT isn't set
});

Heroku automatically sets the PORT variable, so as long as your config reads it, this should resolve port-related binding issues.

2. Fix Database Configuration (Critical for Production)

Strapi's default SQLite database doesn't work on Heroku—Heroku's ephemeral file system means your database will be wiped on dyno restarts, and it can even prevent your app from starting entirely. Here's what to check:

  • Add the PostgreSQL Add-on: Make sure you've added Heroku Postgres to your app (you can do this via the Heroku Dashboard or with heroku addons:create heroku-postgresql:hobby-dev).
  • Update Database Config: Modify config/database.js to use Heroku's auto-generated DATABASE_URL and enable SSL (required for Heroku Postgres):
module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'postgres',
        uri: env('DATABASE_URL'),
      },
      options: {
        ssl: env.bool('DATABASE_SSL', true),
      },
    },
  },
});

3. Check Your App's Startup Logs (Most Important Step!)

The logs you shared only show the router failing to connect—we need to see why your app crashed during startup. Run this command in your terminal to get real-time logs:

heroku logs --tail

Look for errors like:

  • Failed database connections
  • Missing dependencies (check if package-lock.json or yarn.lock was committed to Git—Heroku needs this to install consistent dependencies)
  • Syntax errors in your code or config files
  • Missing environment variables (like NODE_ENV=production—Heroku sets this by default, but double-check with heroku config)

4. Confirm Your Startup Command

Heroku uses the start script in your package.json to launch your app. Ensure it's set to run Strapi in production mode:

"scripts": {
  "start": "strapi start",
  "develop": "strapi develop",
  "build": "strapi build",
  "strapi": "strapi"
}

If you're using a custom build step, make sure it's running correctly (e.g., strapi build should run before starting in production).

5. Ensure All Critical Files Are Committed

Double-check that your Git repo includes:

  • config/ folder (all your Strapi configuration files)
  • package.json and your lock file (package-lock.json or yarn.lock)
  • Any custom code or extensions you've added

Missing these files will cause Heroku to fail to set up or start your app.

Start with checking the detailed startup logs—they'll give you the exact error that's crashing your app, which is the fastest way to resolve this. Let me know what you find!

内容的提问来源于stack exchange,提问作者Kisho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 08:57:38