我正在尝试加载我的自定义 js。但出现错误。
错误如下。
无法注册控制器:通知(控制器/通知控制器)错误:无法解析从 http://localhost:3000/assets/controllers/notification_contr 导入的说明符“@noty”...
│ ├── javascript
│ │ ├── application.js
│ │ ├── controllers
│ │ │ ├── application.js
│ │ │ ├── index.js
│ │ │ ├── notification_controller.js
│ │ └── lib
│ │ └── noty.js
通知控制器.js
import { Controller } from "@hotwired/stimulus"
import Noty from "@noty"
export default class extends Controller {
static targets = [ 'type', 'message' ]
....// some codes.
}
配置/importmap.rb
# 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"
## lib
pin "@noty", to: "app/javascript/lib/noty.js", preload: true
我做错了什么?我还有一些其他问题是,“stimulus.min.js”和“turbo.min.js”文件存在哪里?