未捕获的类型错误:不能在没有“new”的情况下调用类构造函数Controller。

3

我从 "stimulus": "^2.0.0" 迁移到了 "@hotwired/stimulus": "^3.0.0"

但是,在 new _default (message_list_controller.js:1) 处出现了错误Uncaught TypeError: Class constructor Controller cannot be invoked without 'new'

我不确定 message_list_controller.js 出了什么问题,因为我只是从 import { Controller } from "stimulus" 改成了 import { Controller } from "@hotwired/stimulus"

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
    connect() {
        this.scrollToBottom()
    }

    scrollToBottom() {
        this.element.scrollTop = this.element.scrollHeight
    }
}

有人能建议我如何解决这个问题吗?


1
https://github.com/hotwired/stimulus/issues/433 - Deepak Mahakale
2
看起来这个人找到了一些解决方案,看看它是否适用于你 - https://github.com/hotwired/stimulus/issues/433#issuecomment-926365479 - Deepak Mahakale
1
它可以工作,我将'@hotwired/stimulus'版本从3.0.0升级到了3.0.0-rc.1,并且移除了'loose:true'。 - Romeo
1个回答

6

您可以通过调整tsconfig.json并添加以下内容来解决此问题:

{
    "compilerOptions": {
        "target": "es6",
        "module": "esnext",
        "moduleResolution": "node"
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接