我在控制台上收到这条消息,但我找不到解决方案:

Failed to register controller: search (controllers/search_controller) TypeError: The 'stimulus' specifier was a simple specifier, but it has not been remapped to anything. Relative module specifiers must start with './', '../', or '/'.

我正在使用rails 7.0.2importmap.rb安装我的JS.

我试着改变import.map的路由,重新安装刺激文档手册,但没有奏效.

推荐答案

你从你的search_controller.js中的stimulus开始进口.您需要将所有引用从stimulus更改为@hotwired/stimulus:

// import { Controller } from "stimulus"
import { Controller } from "@hotwired/stimulus"

Javascript相关问答推荐

promise .all()永不解决

使用Element.children在前后移动 node

导入图像与内联包含它们NextJS

Angular 拦截器错误处理删除方法问题

如何通过继承contentitable属性的元素捕捉keydown事件?

在JavaScript中检索一些文本

对象和数字减法会抵消浏览器js中的数字

PrivateRoute不是路由组件错误

分层树视图

为什么按钮会随浮动属性一起移动?

实现JS代码更改CSS元素

JS—删除对象数组中对象的子对象

Html文件和客户端存储的相关问题,有没有可能?

类构造函数忽略Reaction Native中的可选字段,但在浏览器中按预期工作

TinyMCE 6导致Data:Image对象通过提供的脚本过度上载

为什么当我更新数据库时,我的所有组件都重新呈现?

在查看网页时,如何使HTML中的按钮工作方式类似于鼠标上的滚轮或箭头键?

在渲染turbo流之后滚动到元素

Clip-Path在网页浏览器(Mozilla、Edge、Chrome)上不能正常工作,但在预览版Visual Code Studio HTML、CSS、JS上却能很好地工作

我不知道如何纠正这一点.