I am trying to install 'react-rails' with 'webpacker'. I added both this gems in my rails gemfile. Versions for ruby, rails & gems are as follows:-
I am not able to run "rails generate react:install" command to generate components/ directory for my React components.
I found that there was an issue in "react-rails-2.2.1/lib/generators/react/install_generator.rb" file for javascript_dir method.
Earlier code:-
def javascript_dir
if webpacker?
Webpacker::Configuration.source_path
.join(Webpacker::Configuration.entry_path)
.relative_path_from(::Rails.root)
.to_s
else
'app/assets/javascripts'
end
end
Code to fix:
def javascript_dir
if webpacker?
Webpacker.config.source_path
.join(Webpacker.config.source_entry_path)
.relative_path_from(::Rails.root)
.to_s
else
'app/assets/javascripts'
end
end
The term Webpacker::Configuration is chnaged to Webpacker.config and method name entry_path is changed to source_entry_path.
This work for me..!! Hope this works for you guys!
I believe this issue also reports the same bug: https://github.com/reactjs/react-rails/issues/775
There's a PR open that will fix that and similar issues with the API change if you'd like to help review: https://github.com/reactjs/react-rails/pull/777
The fix you suggested worked for me.
Going to close this issue, as this has been fixed with #777 . Thanks @BookOfGreg, for your great work to pass this on master.
If you guys get any issues, please feel free to re-open this.
This also has to be changed in
component_generator.rb
to
Webpacker.config.source_path
to run
rails g react:component
or you'll get something like
undefined method 'source_path' for Webpacker::Configuration:Class (NoMethodError)
I'm still having this issue and was wondering if the latest merge fixed it or if there is a workaround on my end that I can do before a fix is released, thanks for all the work you do!
I tried the following steps to reproduce but was OK.
rbenv shell 2.4.1
gem install rails
rails new foo --webpack
cd foo
echo "gem 'react-rails', git: 'https://github.com/reactjs/react-rails.git', branch: 'master'" >> Gemfile
bundle
rails g react:install
rails g react:component page name:string
Can you check if it's fixed by installing the master branch?
gem 'react-rails', git: 'https://github.com/reactjs/react-rails.git', branch: 'master'
Had the same issue, the current master branch fixed it.
I tried the following steps to reproduce but was OK.
rbenv shell 2.4.1 gem install rails rails new foo --webpack cd foo echo "gem 'react-rails', git: 'https://github.com/reactjs/react-rails.git', branch: 'master'" >> Gemfile bundle rails g react:install rails g react:component page name:stringCan you check if it's fixed by installing the master branch?
gem 'react-rails', git: 'https://github.com/reactjs/react-rails.git', branch: 'master'
This one is working with my issue!
Most helpful comment
Had the same issue, the current master branch fixed it.