Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: [commonjs--resolver] No known conditions for "./elements" specifier in "svelte" package #15367

Open
yangfuhai opened this issue Feb 22, 2025 · 4 comments

Comments

@yangfuhai
Copy link

yangfuhai commented Feb 22, 2025

Describe the bug

Button.svelte:

<script lang="ts">

    import type { HTMLButtonAttributes } from 'svelte/elements';

    const { ...rest }: HTMLButtonAttributes = $props();
</script>
<button type="button" {...rest} class="tf-btn nopan nodrag {rest.class}">
    <slot></slot>
</button>

svelte.config.js

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

export default {
    // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
    // for more information about preprocessors
    preprocess: [
        vitePreprocess({
            script: true
        })
    ],
    compilerOptions: {
        // accessors: true,
        customElement: true
    }
};

vite.config.ts

import { defineConfig } from 'vite';
import { resolve } from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import dts from 'vite-plugin-dts';

// https://vitejs.dev/config/
export default defineConfig({
    build: {
        outDir: 'dist',
        emptyOutDir: true,
        minify: true,
        sourcemap: false,
        lib: {
            entry: resolve(__dirname, 'src/index.ts'),
            // formats: ['es'],
            name: 'Tinyflow',
            fileName: 'tinyflow'
        }
    },
    plugins: [svelte({ emitCss: false }), dts({
        rollupTypes: true ,
        // tsconfigPath: './tsconfig.app.json'
    })],

});

then execute npm run build will result in an error: [commonjs--resolver] No known conditions for "./elements" specifier in "svelte" package。

Reproduction

git clone https://github.com/tinyflow-ai/tinyflow
pnpm install
pnpm run build

Logs

System Info

System:
    OS: macOS 15.1.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 8.97 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.1 - /usr/local/bin/npm
    pnpm: 8.15.6 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 133.0.6943.127
    Safari: 18.1.1
  npmPackages:
    svelte: ^5.20.2 => 5.20.2

Severity

blocking all usage of svelte

@yangfuhai
Copy link
Author

If you modify Button.svelte to the following code, this problem will not occur.

<script lang="ts">
    const { ...rest }: any = $props();
</script>
<button type="button" {...rest} class="tf-btn nopan nodrag {rest.class}">
    <slot></slot>
</button>

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Feb 22, 2025

The svelte/elements is just a type declaration module, so when compiled, it converts the import to import "svelte/elements", but since there's no actual code to import, an error happens. Related #15236

@yangfuhai
Copy link
Author

The svelte/elements is just a type declaration module, so when compiled, it converts the import to import "svelte/elements", but since there's no actual code to import, an error happens. Related #15236

The related issue did not provide any solution。

@dummdidumm
Copy link
Member

#15236 (comment) this is the solution. Search your code for a missing import type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants