Windows 10部署Laravel 5.4到Heroku遇递归错误的解决咨询
Hey there! I’ve dealt with this frustrating error before when working with Laravel on Heroku from a Windows machine, so let’s break down the most reliable fixes step by step:
Temporarily disable Laravel’s post-install/update scripts
This is the most common culprit. Laravel’s defaultcomposer.jsonscripts can trigger recursive batch execution on Windows during the Heroku build process. Here’s how to test this:- Open your project’s
composer.jsonfile. - Find the
scriptssection and comment out thepost-install-cmdandpost-update-cmdblocks like this:"scripts": { // "post-install-cmd": [ // "Illuminate\\Foundation\\ComposerScripts::postInstall", // "php artisan optimize" // ], // "post-update-cmd": [ // "Illuminate\\Foundation\\ComposerScripts::postUpdate", // "php artisan optimize" // ] } - Commit the change, then push to Heroku again. If the error goes away, re-enable the scripts one by one to find which specific command is causing the recursion. Often,
php artisan optimizecan be the issue on Windows—you can replace it with a condition to only run on non-Windows environments if needed.
- Open your project’s
Update Composer to the latest version
Older Composer versions had known batch script recursion bugs on Windows. Open your CMD and run:composer self-updateAfter updating, try pushing your changes again.
Use Git Bash instead of CMD
Windows’ native CMD has quirks with batch script execution that Git Bash (part of Git for Windows) handles better. Install Git for Windows, launch Git Bash, navigate to your project directory, and run your push command there:git push heroku main(Replace
mainwith your branch name if needed.)Reinstall Heroku CLI
Corrupted Heroku CLI files on Windows can sometimes cause recursive script issues. Uninstall the Heroku CLI from Windows Settings, download the latest version, reinstall it, and restart your terminal before trying again.Check for circular variable references in .env
While rare, a circular reference in your.envfile (e.g.,VAR1=${VAR2}andVAR2=${VAR1}) can trigger recursive processing during build. Double-check your environment variables to ensure no loops exist.
内容的提问来源于stack exchange,提问作者md asiful haque

