'No route matches [GET] "/packs/js/application.js"
I get an error when trying to reference the javascript packs in my code. Any thoughts on what I might be missing?
application.js
import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
Rails.start()
Turbolinks.start()
require("jquery-3.5.1.min")
require("jquery-ui-1.12.1")
require("dataTables.fnSetFilteringDelay")
require("jquery.dataTables.columnFilter-1.5.6")
require("application_default")
application.html.erb
<%= javascript_pack_tag 'application', 'jquery-3', 'jquery-ui-1', 'jquery', 'FixedHeader-2', 'ColVis-1', 'rails': 'reload' %>
Solution 1:[1]
You're missing corresponding public/packs/js/*.js
files. Two options to fix it:
To just compile your packs and let rails server handle recompilation on refresh
bin/webpack
In development it's better to run dev server. It compiles when your files change.
bin/webpack-dev-server
Note on your file structure and what different tag helpers do:
app/
assets/ # used by sprockets aka rails asset pipeline
stylesheets/
application.css # stylesheet_link_tag 'application'
# this is not old syntax; very much current and recommended in rails 7
javascripts/
application.js # javascript_include_tag 'application'
javascript/ # used by rails webpacker
packs/ # keep this folder neat; don't dump everything in here
application.js # javascript_pack_tag 'application'
# use this file to import packages from node_modules
styles/
application.css # stylesheet_pack_tag 'application'
# must be imported in packs/application.js
# import "styles/application"
node_modules/ # use yarn or npm to add js packages, don't put them in 'packs'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |