瀏覽器控制臺抱怨:
Failed to register controller: test (controllers/test_controller) Error: Unable to resolve specifier 'stimulus'
[源參考的最高行指向錯誤觸發的位置
if (!(name in registeredControllers)) {
importShim(path, 'http://localhost:3000/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js')
.then(module => registerController(name, module, application))
.catch(error => console.error(`Failed to register controller: ${name} (${path})`, error))
}
最后一行指向問題的根源:
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from /*"@hotwired/stimulus-loading"*/'blob:http://localhost:3000/cf2bed28-84d1-496d-a453-7a2818e07002'
eagerLoadControllersFrom("controllers", application)
很明顯,app/javascript/controllers/test-controller.js沒有正確射擊。它的第一行呼叫
import { Controller } from "stimulus"
我覺得很奇怪,因為app/javascript/controllers/application.js包含股票代碼
How does one resolve the specifier 'stimulus'?
import { Application } from "@hotwired/stimulus"
const application = Application.start()
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
uj5u.com熱心網友回復:
你試過這種方式嗎?在 app/javascript/controllers/test-controller.js 上這樣寫
從“@hotwired/stimulus”匯入{控制器};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/527213.html
