Webpacker

Does Hatchbox support Webpacker & Yarn?

Of course! We install Yarn by default on all application servers so you can use Webpacker out of the box.

Webpacker adds itself to the assets:precompile step in Rails so your Webpacker assets will be automatically compiled after the asset pipeline finishes.

A common mistake people make is using Webpacker assets inside the asset pipeline.

These are two separate pipelines and they do not mix in production. You can mistakenly get this to work in development, but this will not work in production. Any assets used in the asset pipeline must be accessible inside the asset pipeline folders.

I'm getting an error compiling assets

If you see the following errors, you probably just need to a quick fix to your webpacker install:

Command "webpack" not found

"/node_modules/.bin/webpack (Errno::ENOENT)"

Your app might be missing the yarn binstub. This is required to install node modules before compiling assets. Add the following file to your repo as bin/yarn

bin/yarn
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

bin/yarn also needs to be marked as executable in git so that it can be run during the precompile stage.

git add --chmod=+x bin/yarn
git commit -m "Add bin/yarn"
git push

Then your next deploy should correctly run Yarn to install the packages at the beginning of the assets precompile.