Uncaught (in promise) TypeError: Illegal constructor at new SvelteElement (index.mjs:1381)

ncl*_*iuf 5 rollup custom-element rollupjs svelte sapper

使用以下语句使用最新的 sapper、svelte、nodeJS 和 rollup 堆栈注册自定义元素时未捕获的承诺。

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
Run Code Online (Sandbox Code Playgroud)

我想提一下,我已经在一个新项目上进行了测试

日志

[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" />
Run Code Online (Sandbox Code Playgroud)

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

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

参考: https : //github.com/sveltejs/svelte/issues/4132

Sip*_*tra 5

如引用的GitHub 问题 中所述,一旦您使用 配置 Svelte 编译器customElements: true,您应该为所有组件提供一个元素标记(使用<svelte:options tag="my-component"/>.

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

当您现在运行该应用程序时,您不应再在控制台中看到错误,而是一个正在运行的应用程序。

  • 那么第三方库呢? (3认同)