Skip to content

Commit b6c13f1

Browse files
justin808claude
andcommitted
Skip version validation when react-on-rails package not installed
The version checker was failing during `rails generate react_on_rails:install` because it ran after package.json was created by shakapacker:install but before the generator had a chance to install the react-on-rails package. Error was: **ERROR** ReactOnRails: No React on Rails npm package is installed. This commit adds an additional check to skip validation if neither react-on-rails nor react-on-rails-pro package is found in package.json, allowing the generator to complete its installation process. The validation will still run normally once the packages are installed, ensuring version compatibility in production apps. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d779040 commit b6c13f1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/react_on_rails/engine.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module ReactOnRails
66
class Engine < ::Rails::Engine
77
# Validate package versions and compatibility on Rails startup
88
# This ensures the application fails fast if versions don't match or packages are misconfigured
9-
# Skip validation during installation tasks (e.g., shakapacker:install)
9+
# Skip validation during installation tasks (e.g., shakapacker:install, react_on_rails:install)
1010
initializer "react_on_rails.validate_version_and_package_compatibility" do
1111
config.after_initialize do
1212
# Skip validation if package.json doesn't exist yet (during initial setup)
@@ -16,6 +16,13 @@ class Engine < ::Rails::Engine
1616
# Skip validation when generators explicitly set this flag (packages may not be installed yet)
1717
next if ENV["REACT_ON_RAILS_SKIP_VALIDATION"] == "true"
1818

19+
# Skip validation if react-on-rails package is not installed yet (during generator run)
20+
# This allows generators to complete before the package is installed
21+
node_package_version = VersionChecker::NodePackageVersion.build
22+
has_base = node_package_version.react_on_rails_package?
23+
has_pro = node_package_version.react_on_rails_pro_package?
24+
next unless has_base || has_pro
25+
1926
Rails.logger.info "[React on Rails] Validating package version and compatibility..."
2027
VersionChecker.build.validate_version_and_package_compatibility!
2128
Rails.logger.info "[React on Rails] Package validation successful"

0 commit comments

Comments
 (0)