Heroku执行jekyll serve报错求助:文件已存在问题
Hey there, let's get this Jekyll + Heroku issue sorted out for you! That error about the existing /app/_site/bin/erb file is happening because Jekyll is trying to copy system-level Ruby bin files (which are symlinks in Heroku's environment) into your _site directory, but those paths already exist from a prior build. Here's how to fix it:
Step 1: Exclude the bin directory from Jekyll's processing
Heroku's Ruby environment has a system bin directory that Jekyll doesn't need to include in your static site. Add bin to your _config.yml's exclude list to tell Jekyll to ignore it entirely:
# _config.yml exclude: ['config.ru', 'Gemfile', 'Gemfile.lock', 'vendor', 'Procfile', 'Rakefile', 'bin']
Step 2: Add a clean build flag to your Procfile
To prevent leftover files from previous builds causing conflicts, add the --clean flag to your jekyll serve command. This forces Jekyll to delete the _site directory before rebuilding:
# Procfile web: bundle exec jekyll serve --port $PORT --host 0.0.0.0 --clean
Step 3: Double-check your gitignore (optional)
If you accidentally committed a local bin directory to your repo, add bin/ to your .gitignore file (except for any custom scripts you need—Heroku handles Ruby's bin files automatically):
# .gitignore bin/
Why this works
On your local machine, your Ruby environment's bin directory structure doesn't create this symlink conflict because Jekyll isn't trying to copy system-level symlinks into your _site folder. But Heroku's containerized environment has these symlinks, and Jekyll's static file handler tries to replicate them—leading to the "file exists" error when a prior build left those paths intact. Excluding bin and forcing a clean build eliminates this conflict entirely.
Bonus: Fixing permalinks with Puma (if you need it later)
If you go back to using Puma with rack-jekyll and hit permalink issues, make sure your config.ru uses the :force_build option to ensure Jekyll generates all static files correctly before Rack serves them:
# config.ru require 'rack/jekyll' run Rack::Jekyll.new(:force_build => true)
This ensures Jekyll finishes building your site with proper permalinks before Puma starts serving content.
内容的提问来源于stack exchange,提问作者Clinton Shane Wright

