How to install Webpacker with rails?

Orsay picture Orsay · Dec 2, 2017 · Viewed 10.5k times · Source

I'm trying to install webpacker to be able to launch 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' (See full trace by running task with --trace)

The command doesn't seems to exist...

Answer

Fabrizio Bertoglio picture Fabrizio Bertoglio · Dec 2, 2017

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