-
-
Notifications
You must be signed in to change notification settings - Fork 633
Open
Description
Environment
- Ruby version: 3.3.7
- Rails version: 8.0.4
- Shakapacker version: 8.4.0 (any version < 9.3.0)
- React on Rails version: 16.2.0-rc.0
Summary
The react_on_rails:install generator fails on fresh installations when using Shakapacker < 9.3.0 because it creates a babel.config.js that requires @babel/preset-react, but doesn't install that dependency.
Expected behavior
Running rails generate react_on_rails:install should produce a working application that builds successfully with webpack.
Actual behavior
Webpack build fails with:
Error: Cannot find package '@babel/preset-react' imported from babel-virtual-resolve-base.js
Root Cause
PR #2051 removed @babel/preset-react from the generator's installed dependencies with the intent that:
- SWC is now the default transpiler (has built-in JSX support)
- Babel users should install presets manually
However, this creates issues because:
- Shakapacker < 9.3.0 uses Babel by default (not SWC)
- The generator still creates
babel.config.jsthat requires@babel/preset-react:// Generated babel.config.js line 11 '@babel/preset-react',
- The dependency is not installed, so webpack fails
Why CI doesn't catch this
The dummy app (spec/dummy) has @babel/preset-react pre-installed in its package.json (legacy from before PR #2051). CI tests against the existing dummy app, not a fresh generator output.
Steps to Reproduce
rails new test_app --minimal
cd test_app
# Add to Gemfile:
# gem "react_on_rails"
# gem "shakapacker", "~> 8.2"
bundle install
git init && git add . && git commit -m "Initial"
rails generate react_on_rails:install
# Start the app
foreman start -f Procfile.dev
# -> Webpack fails with "Cannot find package '@babel/preset-react'"Proposed Fix
Install @babel/preset-react when NOT using SWC:
# js_dependency_manager.rb
BABEL_REACT_DEPENDENCIES = %w[
@babel/preset-react
].freeze
def add_js_dependencies
# ... existing code ...
add_babel_react_dependencies unless using_swc?
# ...
endThis aligns with:
- Shakapacker's own documentation (
docs/react.mdtells users tonpm install @babel/preset-react) - The gemspec supporting Shakapacker >= 6.0
- CI testing against Shakapacker 8.2.0 as minimum
Related
- PR Refactor: Extract JS dependency management into shared module #2051 introduced this change
- Shakapacker
docs/react.mdexplicitly requires@babel/preset-reactfor Babel users - Shakapacker
docs/using_swc_loader.mdconfirms SWC has built-in JSX support (no Babel presets needed)
Metadata
Metadata
Assignees
Labels
No labels