Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console error with lazyLoadControllersFrom and external controller #111

Closed
xdmx opened this issue Nov 8, 2022 · 1 comment
Closed

Console error with lazyLoadControllersFrom and external controller #111

xdmx opened this issue Nov 8, 2022 · 1 comment

Comments

@xdmx
Copy link

xdmx commented Nov 8, 2022

I've noticed that when I load a page with the autocomplete controller I get an error in the console:

Failed to autoload controller: autocomplete Error: Unable to resolve specifier 'controllers/autocomplete_controller' imported from http://localhost:3000/assets/stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js
    throwUnresolved es-module-shims.js:394
    _resolve es-module-shims.js:350
    importShim es-module-shims.js:384
    loadController stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js:70
    lazyLoadExistingControllers stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js:39
    lazyLoadExistingControllers stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js:39
    lazyLoadControllersFrom stimulus-loading-e367296568a6df104dc84fcfe5d1aafae5076fc0.js:34
    <anonymous> index-26693b7cb3885f2275520ffa4aafbe6ea299e699.js:6

I have a pretty basic config:

pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "application", preload: true
pin "stimulus-autocomplete", to: "https://ga.jspm.io/npm:stimulus-autocomplete@3.0.2/src/autocomplete.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from "app/javascript/lib", under: "lib"
import { Application } from "@hotwired/stimulus"
import { Autocomplete } from "stimulus-autocomplete"

const application = Application.start()

application.register("autocomplete", Autocomplete)

application.debug = false
window.Stimulus   = application

export { application }
import { application } from "controllers/application"

import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
lazyLoadControllersFrom("controllers", application)

As soon as I switch to the eager loading the error goes away

import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)

In both cases the autocomplete is working, but it's just noisy to get that error in the console. Should manually registered controllers be excluded by the lazy loading under the controllers path?

I've also tried to remove the preload from pin "application", preload: true since application includes a controller, but nothing changed

@dhh
Copy link
Member

dhh commented Dec 31, 2022

Should be sorted by #113

@dhh dhh closed this as completed Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants