How to import a svelte.ts component from another app where the import is with $lib - Stack Overflow

时间: 2025-01-06 admin 业界

Hi im trying to import a svelte component from another svelte.ts app. This component has a script:

button.svelte:

<script lang="ts">
    import { cn } from "$lib/utils.js";

    let {
        class: className,
        variant = "default",
        size = "default",
        ref = $bindable(null),
        href = undefined,
        type = "button",
        children,
        ...restProps
    }: ButtonProps = $props();
</script>

Here an import is made:

import { cn } from "$lib/utils.js"; 

This import seems to cause an error when I import this component in a complete different svelte.ts app. The error that is caused looks like this:the error appearing In my other app (I want to import the button into) the file tree is the exact same and I also have the utils.js in my lib folder and in my App.svelte I import the original component like this import {Button} from '../../ui/src/lib/components/ui/button/';. I tried setting the aliases in my app but it still doesnt work. Maybe theres a quickfix? If you need more info just ask!

I was expecting that the button could just be imported. But it didnt work!

最新文章