无法将HTML/CSS/JS项目推送至Heroku,报错未检测到默认语言
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:
Create a
package.jsonfile 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
servepackage is a lightweight static file server, and thestartcommand tells Heroku exactly how to run your app.Commit the new file
Run these commands in your terminal:git add package.json git commit -m "Add package.json for Heroku deployment"Push to Heroku again
Run your usual deploy command:git push heroku main(If you're using the old
masterbranch instead ofmain, 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:
Set the buildpack
Run this in your terminal:heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.gitCreate a
static.jsonfile in your project root
This tells the buildpack how to serve your files:{ "root": ".", "clean_urls": false, "routes": { "/**": "index.html" } }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

