未捕获(承诺)TypeError:新SvelteElement处的非法构造函数(index.mjs:1381)

问题描述 投票:2回答:1

[使用最新版本注册自定义元素时未作承诺sapper,svelte,nodeJS和汇总堆栈,使用以下内容声明。

REPL示例https://svelte.dev/repl/489ee8acd10848b0bb1feb2535bd6cc5?version=3.16.5在本地创建

<svelte:options tag="parlax-background" />
    & rollup.config.js
    export default {
    client: {
    input: config.client.input(),
    output: config.client.output(),
    plugins: [
    replace({...})
    svelte({
    dev: !production,
    customElement: true,
    // and tried also with customElement: { tag: "my-element"}
    hydratable: true,
    emitCss: true

[我想提到我已经在一个新项目中测试过

日志

[Client Side]
    => Uncaught (in promise) TypeError: Illegal constructor
    at new SvelteElement (index.mjs:1381)
    [Server Side]
    => The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?
    44: <svelte:options tag="my-element" />

1。当我在配置中注册[** customElement: true时,我得到**

2。如果我没有在配置中注册我的元素,我不会收到任何错误,但是我的元素都没有注册 :(

Ref: https://github.com/sveltejs/svelte/issues/4132

custom-element rollup svelte rollupjs sapper
1个回答
0
投票

如参考文献GitHub issue中所述,一旦将Svelte编译器配置为customElements: true,就应该为all组件(使用<svelte:options tag="my-component"/>提供一个元素标签。

在您的REPL的示例中,这意味着使用以下命令更新App.svelte<svelte:options tag="my-app"/>

当您现在运行该应用程序时,您应该再也无法在控制台中看到该错误,而是可以正常运行的应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.