Skip to content

Fix: Foreman execution fails in bundler context #1832

@AbanoubGhadban

Description

@AbanoubGhadban

Problem

The dummy app's bin/dev script fails with the following error when foreman is not included in the Gemfile:

can't find executable foreman for gem foreman. foreman is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)

However, running foreman start -f Procfile.dev directly works fine.

Root Cause

  1. Foreman is intentionally NOT included in the Gemfile (following React on Rails best practices documented in docs/javascript/foreman-issues.md)
  2. Bundler intercepts system calls when binstubs are active, trying to find foreman within the current bundle context
  3. The ReactOnRails process manager calls system("foreman", "start", "-f", procfile) which gets intercepted by bundler

Available Solutions

  1. Add foreman to Gemfile - Goes against documented best practices
  2. Use full path to system foreman - Brittle and platform-dependent
  3. Clear bundle environment - Complex and error-prone
  4. Use Bundler.with_unbundled_env - Clean, purpose-built solution

Chosen Solution

Implement a fallback strategy in ProcessManager:

  1. First attempt: Try running foreman within bundler context (for projects that do include foreman)
  2. Fallback: Use Bundler.with_unbundled_env to run system foreman if bundler context fails
  3. Clear error messaging: If foreman isn't found in either context, provide helpful guidance

Implementation Plan

  • Modify lib/react_on_rails/dev/process_manager.rb with intelligent fallback
  • Add comprehensive error messaging with links to documentation
  • Add tests for the fallback mechanism
  • Ensure compatibility with both bundled and system foreman installations

Benefits

  • Maintains best practices: Keeps foreman out of Gemfile
  • Backwards compatible: Works with projects that do include foreman
  • Better UX: Clear error messages guide users to proper setup
  • Robust: Handles both bundled and system foreman installations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions