Skip to content

Commit d4f7d8e

Browse files
ihabadhamclaude
andcommitted
Fix generator inheriting BUNDLE_GEMFILE from parent process
Wrap bundler commands in install_generator.rb with Bundler.with_unbundled_env to prevent BUNDLE_GEMFILE inheritance from the parent process. This fixes "injected gems" conflicts when running `bundle exec rails g react_on_rails:install`. The issue occurs because system() calls inherit the parent's BUNDLE_GEMFILE environment variable, causing bundler to use the wrong Gemfile when the generator runs bundle commands. This is a well-documented Bundler issue (rubygems/bundler#698, rails/rails#3153) and the fix follows the official solution recommended by Bundler maintainers since 2012. Fixes #2287 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 619cb78 commit d4f7d8e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

react_on_rails/lib/generators/react_on_rails/install_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def ensure_shakapacker_in_gemfile
263263
return if shakapacker_in_gemfile?
264264

265265
puts Rainbow("📝 Adding Shakapacker to Gemfile...").yellow
266-
success = system("bundle add shakapacker --strict")
266+
success = Bundler.with_unbundled_env { system("bundle add shakapacker --strict") }
267267
return if success
268268

269269
handle_shakapacker_gemfile_error
@@ -274,14 +274,14 @@ def install_shakapacker
274274

275275
# First run bundle install to make shakapacker available
276276
puts Rainbow("📦 Running bundle install...").yellow
277-
bundle_success = system("bundle install")
277+
bundle_success = Bundler.with_unbundled_env { system("bundle install") }
278278
unless bundle_success
279279
handle_shakapacker_install_error
280280
return
281281
end
282282

283283
# Then run the shakapacker installer
284-
success = system("bundle exec rails shakapacker:install")
284+
success = Bundler.with_unbundled_env { system("bundle exec rails shakapacker:install") }
285285
return if success
286286

287287
handle_shakapacker_install_error

0 commit comments

Comments
 (0)