2

Following this tutorial I am stepping into odd errors in the very first steps.

After running:

rails new rails-react-tutorial --webpack=react

I would then try after bundle install

rails webpacker:install:react  rails generate react:installyarn install 

And I will get:

[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
rails aborted!
ArgumentError: Malformed version number string Yarn v0.1.1 2011 Jesper Kjeldgaard
/*/rails-react-tutorial/bin/rails:9:in `<top (required)>'
/*/rails-react-tutorial/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => webpacker:install:react => webpacker:verify_install => webpacker:check_yarn
(See full trace by running task with --trace)

After checking this issue, I have removed the yarn files in the bin paths for the gems as it's advised in the last comments versions/2.6.1/lib/ruby/gems/2.6.0/gems/yarn-0.1.1/lib/yarn.rb, but then I get errors like:

rails webpacker:install:react
rails aborted!
LoadError: cannot load such file -- /*/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/yarn-0.1.1/lib/yarn.rb
/*/rails-react-tutorial/config/application.rb:7:in `<main>'
/*/rails-react-tutorial/Rakefile:4:in `<main>'
/*/rails-react-tutorial/bin/rails:9:in `<top (required)>'
/*/rails-react-tutorial/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

So that will force me to install the gem again. I am using Rails 6.0.2.1-v and ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux].

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Gotey
  • 449
  • 4
  • 15
  • 41

2 Answers2

2

The yarn tool you need is not a gem but the Yarn package manager. I suspect you have installed the yarn gem which appears to be an old unused unrelated project.

Try on your command line:

gem uninstall yarn

Make sure you have the Yarn package manager installed. On a Mac, you can use Homebrew:

brew install yarn

Then retry the project installation commands, which should be:

rails webpacker:install:react 
rails generate react:install
yarn install
rossta
  • 11,394
  • 1
  • 43
  • 47
  • Doing that and later trying: `rails new exampleproject --webpack=react` I get ` rbenv: yarn: command not found The `yarn' command exists in these Ruby versions: 2.6.2 Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/ ` Although now I am using ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-li – Gotey Dec 22 '19 at 18:55
  • 1
    Is it on your path? i.e., `which yarn` – rossta Dec 22 '19 at 19:05
  • Yes `***/.rbenv/shims/yarn` – Gotey Dec 22 '19 at 19:11
  • I've tried installing ruby 2.6.2 and setting it as default with `$ rvm use ruby-2.6.2 --default` and then I get ` `to_specs': Could not find 'railties' (>= 0.a) among 47 total gem(s) (Gem::LoadError) Checked in 'GEM_PATH=***/.rvm/gems/ruby-2.6.2:/****/.rvm/gems/ruby-2.6.2@global', execute `gem env` for more information ` – Gotey Dec 22 '19 at 19:12
  • If I use `gem install railties` , then trying the same command to build the app `rails new example --webpack=react` I am getting: `block in materialize': Could not find nokogiri-1.10.7 in any of the sources (Bundler::GemNotFound) Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/ ` ( this executes after `rails webpacker:install ` ) – Gotey Dec 22 '19 at 19:40
  • That will give this sort of problems: ` Traceback (most recent call last): 1: from /*/.rbenv/versions/2.6.1/bin/bundle:22:in
    ' /*/.rbenv/versions/2.6.1/bin/bundle:22:in load': cannot load such file -- /*l/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundle (LoadError) `
    – Gotey Dec 23 '19 at 12:29
  • I am getting this now solely with the `webpack:react` flag : ` ruby-2.6.2/gems/bundler-2.1.2/lib/bundler/rubygems_integration.rb:374:in block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception) ` – Gotey Dec 23 '19 at 13:13
  • Try removing the yarn gem from the system with `gem cleanup yarn`. Repeat: you don't want any version of the `yarn` gem on your system. – rossta Dec 23 '19 at 14:58
  • Hi, I have done that and it keeps prompting that error – Gotey Dec 23 '19 at 14:59
  • I have solved the issue, I posted the used code above – Gotey Dec 23 '19 at 15:18
2

I found this here and solved the issue:

for ver in $(rbenv whence yarn); do
  RBENV_VERSION="$ver" gem uninstall -ax yarn
  rm -f "$(rbenv prefix "$ver")/bin/yarn"
done
rbenv rehash
Gotey
  • 449
  • 4
  • 15
  • 41