Reputation: 1875
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
Download and activate VirtualBox image for Ubuntu 20.04.2 Focal Fossa from https://www.osboxes.org/ubuntu/
Install Rails 6.1.3.2, Ruby 3.0.1 and Node.js 12 following this guide to the letter (using rbenv)
Create a new app
rails new testapp
cd testapp
rails generate scaffold Product name:string
rails db:migrate
rails server
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)
bundle exec rails webpacker:install
npm install webpack-dev-server -g
yarn add webpack
yarn install --check-files
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
Reputation: 1875
Problem occurs only if a Rails app is created in a shared folder on guest OS.
Solution
VBoxManage setextradata "VMNAME" VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARENAME 1
(change VMNAME
and SHARENAME
)touch test
ln -s test test-symlink
Should produce no errorDetails
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