bizzz
bizzz

Reputation: 1875

Webpacker error on a vanilla Rails installation

I'm repeatedly failing the first step in a basic Ruby-on-rails tutorial after installing all dependencies for Rails on a fresh Ubuntu 20.04 VM.

The error that I get in the server console after creating a vanilla controller through scaffold and trying to access it

[Webpacker] Compilation failed:
error Command "webpack" not found.

Steps to reproduce

  1. Download and activate VirtualBox image for Ubuntu 20.04.2 Focal Fossa from https://www.osboxes.org/ubuntu/

  2. Install Rails 6.1.3.2, Ruby 3.0.1 and Node.js 12 following this guide to the letter (using rbenv)

  3. Create a new app

    rails new testapp
    cd testapp
    rails generate scaffold Product name:string
    rails db:migrate
    rails server
    
  4. Go to http://127.0.0.1:3000/ -- works as expected
    Go to http://127.0.0.1:3000/products -- produces the error

Things I've tried that failed (each with a fresh Ubuntu image)

  1. bundle exec rails webpacker:install
  2. npm install webpack-dev-server -g
  3. yarn add webpack
  4. yarn install --check-files
  5. Installing Ruby globally without rbenv
  6. Installing Rails following other guides from Google results for "rails install ubuntu 20"
  7. Installing Node.js 16 or 14
  8. Using Ubuntu version 21 or 18

Utterly defeated I turn to you, fellow people, for help


Verbose error seen in the browser

Webpacker::Manifest::MissingEntryError in Products#index

Showing /media/sf_coding/testapp/app/views/layouts/application.html.erb where line #10 raised:

Webpacker can't find application.js in /media/sf_coding/testapp/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}

Extracted source (around line #10):   

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>

Also, might be relevant, this warning while creating a new rails app

warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0"

Upvotes: 0

Views: 406

Answers (1)

bizzz
bizzz

Reputation: 1875

Problem occurs only if a Rails app is created in a shared folder on guest OS.

Solution

  1. Enable symlinks in the host OS:
    VBoxManage setextradata "VMNAME" VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARENAME 1 (change VMNAME and SHARENAME)
  2. Check that it worked in the shared folder on guest OS
    touch test
    ln -s test test-symlink 
    
    Should produce no error
  3. Recreate your Rails app or reinstall all dependencies via bundler

Details
I've wanted to use guest OS (Ubuntu) as a server, not to clutter my host OS with all the stuff needed to run Rails. But I also wanted to write code in the luxury of my favorite text editor on my host OS.

So I've created the Rails in a shared folder on the guest OS and that is where the problem came from.
I didn't mention the shared folder use in the initial question as I did not think is was something substantial. Alas, it was very substantial.

My guess is that symlinks which are needed for Webpack to work are not being created.
Symlinks are disabled in Virtualbox by default as a security precaution against malicious guest OSes overrunning a host OS.

Upvotes: 1

Related Questions