【问题标题】:Uncaught (in promise) TypeError: Illegal constructor at new SvelteElement (index.mjs:1381)Uncaught (in promise) TypeError: Illegal constructor at new SvelteElement (index.mjs:1381)
【发布时间】:2019-12-29 07:31:19
【问题描述】:

使用最新的注册自定义元素时未捕获的承诺 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

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

日志

[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。如果我没有在配置中注册我的元素,我不会收到任何错误,但我的元素都没有注册 :(

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

【问题讨论】:

    标签: custom-element rollup svelte rollupjs sapper


    【解决方案1】:

    如引用的GitHub issue 中所述,一旦您使用customElements: true 配置Svelte 编译器,您需要为您的所有 组件提供一个元素标记(使用&lt;svelte:options tag="my-component"/&gt;

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

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

    【讨论】:

    • 第三方库呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    相关资源
    最近更新 更多