Skip to content

Not possible to create a web component from more than one .svelte file #4571

Closed
@thojanssens

Description

@thojanssens

I have a DatePicker component, composed of different .svelte files.

I added <svelte:options tag="date-picker"/> only in the main DatePicker.svelte component, but when running npm run build, I got the error message:

(!) Plugin svelte: No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use
<svelte:options tag={null}/>

Then I tried adding that option in every .svelte component; the message disappeared, but when viewing the component in the browser, I had the error message:

Failed to execute 'define' on 'CustomElementRegistry': the name "date-picker" has already been used with this registry

This is the rollup file:

import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import pkg from './package.json';

const name = pkg.name
	.replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
	.replace(/^\w/, m => m.toUpperCase())
	.replace(/-\w/g, m => m[1].toUpperCase());

export default {
	input: 'src/index.js',
	output: [
		{ file: pkg.module, 'format': 'es' },
		{ file: pkg.main, 'format': 'umd', name }
	],
	plugins: [
		svelte({
			customElement: true
		}),
		resolve()
	]
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions