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

Heroku部署Node.js应用失败:执行nodemon而非node命令

Fix Heroku Using Nodemon Instead of node app.js for Your Node.js App

Oh man, I’ve been in this exact spot before—Heroku clinging to old start commands even after you update your package.json is such a frustrating gotcha. Let’s walk through how to fix this step by step:

  • Double-check your package.json scripts
    First, make sure your start script is explicitly set to node app.js and there’s no leftover nodemon reference. Your scripts section should look something like this:

    "scripts": {
      "start": "node app.js",
      "dev": "nodemon app.js" // It’s totally fine to keep this for local development!
    }
    

    Heroku defaults to using the start script unless told otherwise, so this is your primary fallback.

  • Check for a Procfile (and fix it if it exists)
    Heroku prioritizes the Procfile over package.json’s start script. If you have one in your project root, open it up—if it says web: nodemon app.js, change it to web: node app.js. If you don’t need a Procfile (since package.json’s start works perfectly), you can just delete it entirely.

  • Clear Heroku’s cache to wipe old configurations
    Sometimes Heroku caches old build settings, which makes it ignore your new changes. Run these commands in your terminal to clear the cache and trigger a fresh deploy:

    heroku config:set NODE_MODULES_CACHE=false
    git commit -am "Clear Heroku cache" --allow-empty
    git push heroku main
    # Once deployed, you can re-enable cache to speed up future builds:
    heroku config:set NODE_MODULES_CACHE=true
    

    The empty commit is just a quick trick to trigger a new build without altering your actual code.

  • Verify your changes were actually pushed
    It sounds obvious, but double-check that you’ve committed your updated package.json/Procfile before pushing to Heroku. Run git status to confirm all changes are staged, then git commit and git push heroku main again if needed.

  • Inspect the deployed app’s files (just to be 100% sure)
    If you’re still stuck, you can hop into the Heroku dyno to confirm your package.json is up-to-date:

    heroku run bash
    cat package.json
    

    This will show you exactly what’s on Heroku—if it’s still the old version, you know your push didn’t go through properly.

Once you’ve worked through these steps, redeploy and check the logs with heroku logs --tail—you should see Heroku starting with node app.js instead of nodemon, and your app should spin up without crashing.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:29:56