[英]Can't import a Stimulus component to my Rails application: Uncaught TypeError: Failed to resolve module specifier
嘗試遵循此 NestedForm Stimulus 組件的設置指南: 安裝
像這樣:
$ npm install stimulus-rails-nested-form --save
應用程序/javascript/controllers/application.js
import { Application } from "@hotwired/stimulus"
import NestedForm from 'stimulus-rails-nested-form' // Added this
const application = Application.start()
application.register('nested-form', NestedForm) // Added this
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
我得到:
Uncaught TypeError: Failed to resolve module specifier "stimulus-rails-nested-form". Relative references must start with either "/", "./", or "../".
我可以看到 package 已正確安裝在 node_modules 目錄中,並且 Stimulus 正在正確加載,因為我在應用程序的其他地方使用它。
我在 Rails 7.0.4 上。
感謝任何幫助,干杯!
如果您分享更多關於您的 Rails 設置的信息,那可能會有所幫助。
你的 Rails 應用程序可能不知道你的 javascripts...看看這里: https://guides.rubyonrails.org/working_with_javascript_in_rails.html
您將需要使用 importmaps(在這種情況下您不需要 npm),或者您使用 esbuild 或 webpack(我不推薦后者)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.