部署基于Puppeteer的Node.js爬虫至Heroku遇H14错误求助
Let's work through your Heroku deployment issues one by one—first fixing the "No web processes running" and "Couldn't find that process type (web)" errors, then making sure Puppeteer plays nice with Heroku's environment.
1. Fix the Missing Web Process Error
Heroku has no idea what process to start for your app right now—that's why you're getting the "Couldn't find that process type (web)" message. Here's how to fix that with Yarn:
Double-check your
package.jsonstart script
Open up yourpackage.jsonand make sure there's astartcommand in thescriptssection that points to your app's main file (likeindex.jsorserver.js):{ "scripts": { "start": "node index.js" } }Swap
index.jsfor whatever your actual entry file is named.Create a
Procfile
In your project's root folder, make a file namedProcfile(capital P, no file extension—this is important!) with this line:web: yarn startIf your app needs to listen on a port, don't hardcode it—use
process.env.PORTin your Node.js code instead. Heroku assigns this port automatically, so your app will pick it up seamlessly.Deploy and scale the web dyno
Commit your changes and push to Heroku:git add Procfile package.json git commit -m "Set up web process for Heroku deployment" git push heroku mainNow run the scale command again—it should work without the error this time:
heroku ps:scale web=1
2. Get Puppeteer Running Smoothly on Heroku
You've already added the right buildpacks, but there's a key configuration step you might be missing for Puppeteer:
Add mandatory launch arguments
Heroku runs in a headless, restricted environment, so Puppeteer needs specific flags to start up without crashing. Update your launch code to include these args:const puppeteer = require('puppeteer'); async function runScraper() { const browser = await puppeteer.launch({ args: [ '--no-sandbox', // Disables sandbox (required for Heroku's environment) '--disable-setuid-sandbox', '--disable-dev-shm-usage', // Fixes issues with limited shared memory on Heroku '--headless=new', // Uses the modern, more stable headless mode '--single-process' ] }); // Your scraping logic goes here... await browser.close(); }Confirm buildpack order
Heroku runs buildpacks in the order they're added, so make sure the Node.js buildpack comes before the Puppeteer one. Check your current buildpacks with:heroku buildpacksIf they're out of order, fix it with these commands:
heroku buildpacks:add --index 1 heroku/nodejs heroku buildpacks:add --index 2 https://github.com/jontewks/puppeteer-heroku-buildpack.git
3. Debug with Logs If You Still Hit Issues
If something's still not working, pull up Heroku's logs to see exactly what's going wrong:
heroku logs --tail
This will show you detailed error messages—like if Puppeteer is failing to launch, or your web server is crashing for some other reason.
内容的提问来源于stack exchange,提问作者sale108

