Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript_dir': undefined method source_path' for Webpacker::Configuration:Class (NoMethodError) #778

Closed
vikash22292 opened this issue Sep 1, 2017 · 8 comments

Comments

@vikash22292
Copy link

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:-

  1. Ruby: 2.4.1
  2. Rails: 5.1
  3. react-rails gem: 2.2.1
  4. webpacker: 3.0.0

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!

@vikash22292 vikash22292 changed the title javascript_dir': undefined method source_path' for Webpacker::Configur0ation:Class (NoMethodError) javascript_dir': undefined method source_path' for Webpacker::Configuration:Class (NoMethodError) Sep 1, 2017
@fresham
Copy link

fresham commented Sep 1, 2017

I believe this issue also reports the same bug: #775

There's a PR open that will fix that and similar issues with the API change if you'd like to help review: #777

@benaubin
Copy link

benaubin commented Sep 2, 2017

The fix you suggested worked for me.

@vikash22292
Copy link
Author

vikash22292 commented Sep 13, 2017

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.

@ElishebaW
Copy link

ElishebaW commented Sep 16, 2017

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)

@gaiapunk
Copy link

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!

@BookOfGreg
Copy link
Member

BookOfGreg commented Sep 20, 2017

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'

@thealexauer
Copy link

Had the same issue, the current master branch fixed it.

masahikokawai added a commit to masahikokawai/rails5.1-react-redux-app that referenced this issue Nov 28, 2017
@iyamus
Copy link

iyamus commented Feb 15, 2020

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'

This one is working with my issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants