Search code examples
ruby-on-railsruby-on-rails-6webpacker

The application.js file is being ignored by webpacker compilation in rails 6


In a rails 6 application upgraded from rails 5 I have the following pack files

#app/javascript/packs/application.js
import "core-js/stable";
import "regenerator-runtime/runtime";
require("trix")
require("@rails/actiontext")

and

#app/javascript/packs/application.scss
@import '../stylesheets/datatables.scss';

The webpack-dev-server server compiles successfully, but the javascript included in the application.js file is not running. Indeed if I change require("trix") to require("no_such_file") it does not cause a compilation error, so my application.js is being completely ignored. How do I fix this?


Solution

  • The problem is related to the this webpacker issue (or feature). It seems that if you have another file called application in the packs directory, e.g. application.scss, then webpacker overwrites the output of application.js. Basically I needed to move application.scss out of the packs directory and import it in the application.js file. This post in the issue report explains this in more detail.