narrow-magazine-18722
07/04/2023, 9:00 AMnarrow-magazine-18722
07/04/2023, 9:00 AMruby
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
# Avo custom JS entrypoint
pin "avo.custom", preload: true
avo.custom.js
js
import ProductResourceController from './controllers/product_resource_controller'
// Hook into the stimulus instance provided by Avo
const application = window.Stimulus
application.register('product-resource', ProductResourceController)
// eslint-disable-next-line no-console
console.log('Hi from Avo custom JS ๐')
avo.custom-7fd8cfcdfff885e9d874f43f614549257254a1fc419bf90a92a0790beb76f174.js:1 GET https://my.domain.com/assets/controllers/product_resource_controller net::ERR_ABORTED 404
also the ๐ does not printnarrow-magazine-18722
07/04/2023, 9:02 AM./bin/importmap json
results locallyloud-jewelry-99127
07/04/2023, 9:03 AMnarrow-magazine-18722
07/04/2023, 9:04 AMloud-jewelry-99127
07/04/2023, 9:05 AMnarrow-magazine-18722
07/04/2023, 9:06 AMbin/importmap json
on production as well, and the two missing items compared to my local run are avo.custom
and controllers/product_resource_controller
narrow-magazine-18722
07/04/2023, 9:08 AMW, [2023-07-04T02:03:06.133880 #59546] WARN -- : Importmap skipped missing path: avo.custom.js
W, [2023-07-04T02:03:06.133985 #59546] WARN -- : Importmap skipped missing path: controllers/product_resource_controller.js
narrow-magazine-18722
07/04/2023, 9:09 AM2.35.0
importmap-rails (1.1.5)
rails (7.0.4.3)
loud-jewelry-99127
07/04/2023, 9:09 AMnarrow-magazine-18722
07/04/2023, 9:10 AMavo:js:install
generator and added my controller as aboveloud-jewelry-99127
07/04/2023, 9:14 AMavo.custom.js
is on the wrong dir
2 - avo.custom.js
is on the right dir but the configured path is wrong
I'm not the best person to help you with this issue, maybe @lemon-wall-20836 can understand this betternarrow-magazine-18722
07/04/2023, 9:20 AMlemon-wall-20836
07/04/2023, 9:26 AMlemon-wall-20836
07/04/2023, 9:27 AMnarrow-magazine-18722
07/04/2023, 9:29 AMavo.custom
asset correctly (which makes sense because that is the only ref to the controller)
I tried bumping Rails.application.config.assets.version
for fun to no effectlemon-wall-20836
07/04/2023, 9:30 AMlemon-wall-20836
07/04/2023, 9:30 AMnarrow-magazine-18722
07/04/2023, 9:30 AMavo.custom
file is correctlemon-wall-20836
07/04/2023, 9:31 AMnarrow-magazine-18722
07/04/2023, 9:32 AMimport
statement -- it's trying to load just assets/controllers/product_resource_controller
and not the version with the precompiled hash in the filenamenarrow-magazine-18722
07/04/2023, 9:33 AMlemon-wall-20836
07/04/2023, 9:36 AMeagerLoadControllersFrom
method?
https://cdn.discordapp.com/attachments/1125712633320980551/1125721785787240550/CleanShot_2023-07-04_at_12.36.23.pngโพ
narrow-magazine-18722
07/04/2023, 9:37 AMindex.js
javascript
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)
The controller is inside ./controllers
lemon-wall-20836
07/04/2023, 9:40 AMimportmap.rb
file looks like?lemon-wall-20836
07/04/2023, 9:40 AMhttps://cdn.discordapp.com/attachments/1125712633320980551/1125722751630589972/CleanShot_2023-07-04_at_12.40.14.pngโพ
lemon-wall-20836
07/04/2023, 9:40 AMpin_all_from "app/javascript/avo_controllers", under: "avo_controllers"
lemon-wall-20836
07/04/2023, 9:40 AMlemon-wall-20836
07/04/2023, 9:40 AMnarrow-magazine-18722
07/04/2023, 9:41 AMavo_controllers
?lemon-wall-20836
07/04/2023, 9:41 AMlemon-wall-20836
07/04/2023, 9:41 AMlemon-wall-20836
07/04/2023, 9:41 AMcontrollers
?narrow-magazine-18722
07/04/2023, 9:41 AMlemon-wall-20836
07/04/2023, 9:42 AMlemon-wall-20836
07/04/2023, 9:42 AMnarrow-magazine-18722
07/04/2023, 9:43 AMdiff
-import ProductResourceController from './controllers/product_resource_controller'
+import { default as ProductResourceController } from 'controllers/product_resource_controller'
I'm trying this in the meantimelemon-wall-20836
07/04/2023, 9:46 AMimport "controllers"
in your avo.custom.js
file?narrow-magazine-18722
07/04/2023, 9:47 AMjavascript
import { default as ProductResourceController } from 'controllers/product_resource_controller'
// Hook into the stimulus instance provided by Avo
const application = window.Stimulus
application.register('product-resource', ProductResourceController)
// eslint-disable-next-line no-console
console.log('Hi from Avo custom JS ๐')
The diff above is that first linelemon-wall-20836
07/04/2023, 9:48 AMlemon-wall-20836
07/04/2023, 9:48 AMhttps://cdn.discordapp.com/attachments/1125712633320980551/1125724755262197781/CleanShot_2023-07-04_at_12.48.03.pngโพ
narrow-magazine-18722
07/04/2023, 9:48 AMlemon-wall-20836
07/04/2023, 9:48 AMproduct_resource_controller.js
?narrow-magazine-18722
07/04/2023, 9:48 AM./controllers/
vs controllers/
?lemon-wall-20836
07/04/2023, 9:49 AMlemon-wall-20836
07/04/2023, 9:50 AMcontrollers
should work too because that's how the dir is defined in importmap.rbnarrow-magazine-18722
07/04/2023, 9:50 AMcourses_controller
from https://docs.avohq.io/2.0/stimulus-integration.html#custom-stimulus-controllersnarrow-magazine-18722
07/04/2023, 9:51 AMcourse_resource_controller
ratherlemon-wall-20836
07/04/2023, 9:51 AMexport default class extends Controller
statement usually is imported as import NAME from 'controllers/NAME.js
lemon-wall-20836
07/04/2023, 9:51 AMlemon-wall-20836
07/04/2023, 9:52 AMnarrow-magazine-18722
07/04/2023, 9:52 AMimport { default as ProductResourceController } from 'controllers/product_resource_controller'
yeslemon-wall-20836
07/04/2023, 9:52 AMlemon-wall-20836
07/04/2023, 9:52 AMnarrow-magazine-18722
07/04/2023, 9:53 AM./
, I'll try import ProductResourceController from 'controllers/product_resource_controller'
next time I deploynarrow-magazine-18722
07/04/2023, 9:53 AMlemon-wall-20836
07/04/2023, 9:53 AMlemon-wall-20836
07/04/2023, 9:53 AM