-
-
Notifications
You must be signed in to change notification settings - Fork 638
Description
Pack Generation Fails When Running bin/dev Due to Bundler Auto-Exec Interception
Environment
- react_on_rails: 16.2.0.beta.11
- Ruby: 3.4.6
- Bundler: 2.4.17
- Rails: 8.1.1
Problem
When running bin/dev, pack generation fails with:
📦 Generating packs... ✅
Running `bundle react_on_rails:generate_packs` with bundler 2.4.17
Could not find command "react_on_rails:generate_packs".
❌ Pack generation failed
The pack generation actually succeeds (note the ✅), but then Bundler tries to execute bundle react_on_rails:generate_packs as a gem executable command instead of bundle exec rake react_on_rails:generate_packs, which fails.
Root Cause
In lib/react_on_rails/dev/pack_generator.rb, the run_via_bundle_exec method (lines 143-152) uses:
system("bundle", "exec", "rake", "react_on_rails:generate_packs")When this is called from within an existing Bundler context (which is the case when running bin/dev), Bundler intercepts the system call and tries to parse the arguments. It sees "react_on_rails:generate_packs" and attempts to execute it as a gem executable via Bundler's auto-exec feature, rather than passing it through to rake.
The logic tries to avoid this by checking should_run_directly? (lines 66-73), which returns false when Rails isn't loaded. Since bin/dev doesn't load Rails (it shouldn't need to), it falls back to run_via_bundle_exec, triggering the bug.
Reproduction
# When already in a Bundler context:
require 'bundler/setup'
result = system('bundle', 'exec', 'rake', 'react_on_rails:generate_packs')
# => First runs the rake task successfully via direct invocation
# => Then Bundler intercepts and tries: bundle react_on_rails:generate_packs
# => Fails with "Could not find command"Solution
The run_via_bundle_exec method should use Bundler.with_unbundled_env to prevent Bundler from intercepting the subprocess call:
def run_via_bundle_exec(silent: false)
# Need to unbundle to prevent Bundler from intercepting our bundle exec call
with_unbundled_context do
if silent
system(
"bundle", "exec", "rake", "react_on_rails:generate_packs",
out: File::NULL, err: File::NULL
)
else
system("bundle", "exec", "rake", "react_on_rails:generate_packs")
end
end
end
def with_unbundled_context(&block)
if defined?(Bundler)
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&block)
elsif Bundler.respond_to?(:with_clean_env)
Bundler.with_clean_env(&block)
else
yield
end
else
yield
end
endNote: The with_unbundled_context method already exists in process_manager.rb (lines 120-129) and could be extracted to a shared module or copied to pack_generator.rb.
Workaround
Until fixed, users can:
- Manually run
bundle exec rake react_on_rails:generate_packsfirst - Then start foreman/overmind directly with the Procfile
Or patch the gem locally to add the with_unbundled_env wrapper.
Impact
This affects all users of bin/dev in react_on_rails 16.2.0.beta.11 when:
- Running from a Bundler context (which is typical)
- Rails isn't pre-loaded (which is normal for bin/dev)