I am working on a rails 7 app that is using importmaps for all JS related stuff. For reference, I am giving the code below.
importmap.rb
# Pin npm packages by running ./bin/importmap
pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
# Jquery related pins
pin "jquery", to: "https://code.jquery.com/jquery-3.6.0.min.js"
pin "jquery-easing", to: "https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js"
# end jquery related pins
# JS inside app/javascript
pin "sb-admin-2.min"
pin_all_from "app/javascript/demo", under: "demo"
# JS inside app/javascript
# JS inside vendor/javascript
# pin_all_from "vendor/javascript/charts", under: "charts"
pin "charts/Chart.bundle.min"
pin "charts/Chart.min"
# JS inside vendor/javascript
application.js ( app/javasript/application.js)
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
// import jquery and jquery-easing
import "jquery"
import "jquery-easing"
// import jquery and jquery-easing
console.log($)
// import app/javascript
import "sb-admin-2.min"
import "demo/chart-area-demo"
// import app/javascript
// import vendor/javascript
import "charts/Chart.bundle.min"
import "charts/Chart.min"
// import vendor/javascript
PROBLEM
My problem is when I land on this page, my console.log($) does not show any thing nor give any error in console. Same in the case of my charts. but when I myself refresh the page , it then shows the console.log($) and charts starts working too.