How to install Webpacker with Rails - ruby-on-rails

I'm trying to install Webpacker to be able to launch a Yarn server. I'm on Rails 5 and the gem is installed.
When I run
bundle exec rails webpacker:install
I get:
>> rails aborted!
Don't know how to build task 'webpacker:install' (see --tasks)
bin/rails:15:in `require'
bin/rails:15:in `<main>'
(See full trace by running task with --trace)
The command doesn't seem to exist.

install the rails/webpacker gem as from the documentation I am quoting
Installation
You can either add Webpacker during setup of a new Rails 5.1+ application using new --webpack option:
Available Rails 5.1+
rails new myapp --webpack
Or add it to your Gemfile:
Gemfile
gem 'webpacker', '~> 3.0'
OR if you prefer to use master
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
and finally, run following to install Webpacker:
bundle
bundle exec rails webpacker:install
OR (on rails version < 5.0)
bundle exec rake webpacker:install

First, add the following to the gemfile:
gem "webpacker", "~> 3"
Then, bundle install:
bundle exec rails webpacker:install

I was trying to install webpacker and, for me, the solution was a bit different from those listed here.
I was trying gem install webpacker, but it doesn't change the Gemfile.
Then I searched for why it doesn't change, and to make it work I had to use:
bundle add webpacker
After that I used:
rails webpacker:install

Are you sure webpacker is installed correctly?
Maybe there is an issue with your use of bundle exec try running without it. You can also try running with the --tasks flag to verify if the webpacker tasks are available to use.

Related

Rails keeps looking for a non-existent gem

I've replaced the gem mysql2 for a sqlite3 in development environment. However Rails keeps looking for it. I've tried to delete Gemfile.lock and it didn't work. I've also changed the database.yml file.
This is the error when I do rails db:create
LoadError: cannot load such file -- /home/gn09/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/arel-9.0.0/lib/arel/visitors/mysql.rb
replace gem in Gemfile
#gemfile.rb
gem 'sqlite3'
database.yml
something like this
bundle
bundle update - update Gemfile.lock correctly
rails db:create db:migrate
rails s
First uninstall ruby
rbenv uninstall 2.6.1
Then install again to get a fresh set of gems
rbenv uninstall 2.6.1
Then install bundler
gem install bunder -v '2.1.4'
Then
bundle install

Capistrano version conflict

I'm trying to upload my Rails app with:
bin/cap production deploy
but the deployment is failing with this error message:
You have requested:
capistrano ~> 3.3.0
The bundle currently has capistrano locked at 3.7.1.
Try running `bundle update capistrano`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
I tried to fix the issue by running:
bundle update capistrano
but that did not solve it.
The thing I don't get is that I don't see where my application 'asks for capistrano 3.3.0'. In my Gemfile I set Capistrano to version 3.7.
Besides the capistrano gem I'm also using:
gem capistrano-rails, '~> 1.2'
gem capistrano3-delayed-job, '~> 1.3'
gem capistrano-figaro-yml
My Gemfile is at:
https://github.com/acandael/personalsite/blob/master/Gemfile
Does someone know how I can fix this Capistrano version issue?
thanks for your help,
Anthony
Please follow all the steps in the right order (don't skip any because you did it)
cd into your project directory
run bundle exec gem uninstall capistrano -a to remove all capistrano versions from your bundle
run gem uninstall capistrano -a to remove all capistrano versions from your system. Note that you may need to run this with root access if you get an error message
run bundle install
run bundle exec gem list capistrano which should output all installed gems with a name that contains "capistrano". You are supposed to have only one version of the capistrano gem
check in your files config/deploy.rb and config/deploy/*.rb if you have a lock 3.x.x instruction, and make sure it matches the install version as show in step 5
run cap in bundle context with bundle exec cap production deploy (use exactly this command line, do not use bin/cap)
try bundle exec cap production deploy
try to remove YOUR_APP/.bindle directory and run bundle install again

Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile.

I get the following error message when starting the rails server:
Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (12.0.0) has removed it. You'll need to update your bundle to a different version of rake (12.0.0) that hasn't been removed in order to install.
I specified gem 'rake', '12.0.0' in the gemfile but that doesn't fix it. I tried bundle update rake, deleting the Gemfile.lock and generating it with bundle exec bundle install. I also prepended `bundle exec1 to al my commands which does nothing.
My Gemfile.lock already specifies rake version 12.0.0, and there are no other versions installed.
See my gemfile:
http://pastebin.com/L4tVFWz9
And rakefile:
http://pastebin.com/K7p2ajsE
I tried the solutions suggested in Already activated rake version different than what Gemfile requires prevents rake commands
Different methods to solve this issue,
Step1:
gem install rubygems-bundler
gem regenerate_binstubs
Step2:
Remove the vendor/bundle directory.
Run bundle install to rebuild it
Step3:
Try, gem update bundler
Here is a link where the issue got solved. Check this is very useful
Try:
gem install rubygems-bundler
gem regenerate_binstubs
Not really a fundamental solution, but if you really have to run some Rails commands urgently and needs a temporary fix, try bundle exec rails c rather than bin/rails c.
Enter command :-
bundle update rake

Ruby on rails error when running rails s

Um quite new to rails and um getting an error when run the command
rails s
it says
Could not find rake-0.9.2.2 in any of the sources
Run bundle install to install missing gems.
when I run bundle install nothing happened
my gem list has rake 0.9.2.2
what can go wrong?
my ruby version is 1.9.3
Thank you in advance
Remove all the versions of Rake ==> gem uninstall rake
Remove your gemfile.lock => rm Gemfile.lock
Remove gem 'rake' on your gemfile
Run bundle install
Install Rake manually : gem install rake --version=10.0.4
When you use command gem list, you will get a list of gem installed on your machine.
For example : rake (10.0.4, 10.0.3, 0.9.2.2)
Just see the console which gem is compatible with your application. It is already mentioned in the error log message.
Use
gem uninstall rake
Keep the suitable one and remove the version who is creating trouble. And then run rails s or bundle exec rails s
Try using rvm and go back to ruby 1.8.7 instead of 1.9.2. This fixed it for me. Don't forget to install rails again (sudo gem install rails while already on 1.8.7) if you have only installed rails for 1.9.3.]

You have already activated rake 0.9.0, but your Gemfile requires rake 0.8.7

I'm trying to run rails project,
I get
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
If I do: "bundle install"
but
I'm getting
You have already activated rake 0.9.0, but your Gemfile requires rake 0.8.7
while doing
rake db:migrate
First, check to make sure that rake is mentioned in your Gemfile. If it's not, add it, and specify the version "you already activated".
Then, you'll need to tell bundle to update the rake version it's using for your app:
bundle update rake
It'll update your Gemfile.lock for you.
Where you are currently using rake commands like
rake db:migrate
Use this instead:
bundle exec rake db:migrate
this will be the case until the latest version of rails and/or rake work well together.
I thank to Dobry Den, cheers dude. but little more I had to do.
here is solution (works for me).
I had added
gem 'rake','0.8.7'
on Gemfile, which was not there, but my new version of rails automatically install rake(0.9.0).
after I had delete rake0.9.0 by gem uninstall rake
and after doing bundle update rake , I can create and migrate database.
Rake 0.9.0 breaks rails.
See here: Rake 0.9.0 'undefined method 'task' '
Use bundle exec rake instead of rake to run rake at the correct version.
Specify the version that you want in your Gemfile.
gem 'rake', '0.9.0'
then
bundle update rake
you need to use bundle exec to run your rake task
bundle exec rake db:migrate
Oh look, it's the future. For me, it was complaining I had rake 10.x installed when it wanted 0.9.5. Not quite sure, not familiar enough with Ruby to really dig into what happened to the recent version numbers, but what I did was:
gem uninstall rake
gem install rake -v 0.9.5
to force the system to install the version of rake that the app wanted (for me it was Octopress).
I had this problem (with another gem that was not rake) and I was able to fix it by
gem uninstall <complaining gem>
gem install <complaining gem>
bundle install
bundle update
Note that the keyword 'sudo' was not used (ie. sudo bundle install) as that may place your gem into directories where your rails app might not be searching in.
Add this to your Gemfile
# Rake 0.9.0 break Rails.
gem "rake", "!= 0.9.0"
And then uninstall rake-0.9.0
If I understand what you're not asking, you need to open your Gemfile file and change the line...
gem 'rake', '0.8.7'
...to...
gem 'rake', '0.9.0'

Resources