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

无法将HTML/CSS/JS项目推送至Heroku,报错未检测到默认语言

Fixing Heroku's "No default language could be detected" Error for Static HTML/CSS/JS Projects

Hey there! Let's get that static project deployed to Heroku—this error is super common with plain HTML/CSS/JS apps, and it's easy to fix. Here's what's going on and how to resolve it:

Why This Happens

Heroku automatically tries to detect your project's language by looking for specific files in your root directory (like package.json for Node.js, requirements.txt for Python, etc.). Since static HTML projects don't come with these files out of the box, Heroku can't figure out how to serve your app.

Solution 1: Use Node.js to Serve Static Files (Most Reliable)

This is the simplest approach because Heroku has great Node.js support. Here's what to do:

  1. Create a package.json file in your project root
    Paste this code (update the name/description to match your project):

    {
      "name": "your-static-project",
      "version": "1.0.0",
      "description": "My awesome static HTML/CSS/JS app",
      "scripts": {
        "start": "npx serve -s ."
      },
      "dependencies": {
        "serve": "^14.2.1"
      }
    }
    

    The serve package is a lightweight static file server, and the start command tells Heroku exactly how to run your app.

  2. Commit the new file
    Run these commands in your terminal:

    git add package.json
    git commit -m "Add package.json for Heroku deployment"
    
  3. Push to Heroku again
    Run your usual deploy command:

    git push heroku main
    

    (If you're using the old master branch instead of main, swap that in.)

Solution 2: Use Heroku's Static Buildpack

If you don't want to use Node.js, you can use Heroku's dedicated static buildpack:

  1. Set the buildpack
    Run this in your terminal:

    heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git
    
  2. Create a static.json file in your project root
    This tells the buildpack how to serve your files:

    {
      "root": ".",
      "clean_urls": false,
      "routes": {
        "/**": "index.html"
      }
    }
    
  3. Commit and deploy
    Add the new file, commit, and push to Heroku just like before.

Either of these methods should get your static app up and running on Heroku in no time!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:18:30