Heroku部署Node.js应用失败:执行nodemon而非node命令
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 yourstartscript is explicitly set tonode app.jsand 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
startscript unless told otherwise, so this is your primary fallback.Check for a Procfile (and fix it if it exists)
Heroku prioritizes theProcfileover package.json’s start script. If you have one in your project root, open it up—if it saysweb: nodemon app.js, change it toweb: 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=trueThe 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. Rungit statusto confirm all changes are staged, thengit commitandgit push heroku mainagain 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.jsonThis 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

