gpt4 book ai didi

typescript - 如何修复 `Class constructor LitElement cannot be invoked without ' new'`?

转载 作者:行者123 更新时间:2023-12-03 17:09:43 25 4
gpt4 key购买 nike

我正在使用来自 polymer 的 lit-element 建立一个新项目,build设置包括使用parcel。我也在使用 typescript 来编写我的代码。

我首先初始化 npm 并添加了所有必要的依赖项:

"dependencies": {
"@polymer/lit-element": "^0.6.5",
"@webcomponents/webcomponentsjs": "^2.2.1"
},
"devDependencies": {
"parcel-bundler": "^1.11.0",
"tslib": "^1.9.3",
"typescript": "^3.2.2"
}

现在,当我运行包裹以 index.html 开始时,其中包括:
@webcomponents/webcomponentsjs/webcomponents-bundle.js

我收到一条错误消息:
Class constructor LitElement cannot be invoked without 'new'

根据其他人的建议,我尝试将 tsconfig 目标设置为“es2016”,但这并不能解决错误。

我的元素.ts
import { 
LitElement,
html,
customElement,
property
} from '@polymer/lit-element'

@customElement('ui-text')
export class UiText extends LitElement {
render() {
return html`<p>Hi</p>`
}
}

最佳答案

经过一段时间的挣扎后,似乎包裹(从 v1.12.3 开始)有一个问题,它不考虑浏览器列表,除非 index.htmlpackages.json 在同一文件夹中, package-lock.json , 和 node_modules .在我重新组织了我的源文件并添加了 "browserslist": ["Chrome > 46"] 之后它开始工作正常。

关于typescript - 如何修复 `Class constructor LitElement cannot be invoked without ' new'`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53937200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com