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

unclosed tag in html in a snippet leads to module has no default export error #2681

Open
sukeshpabolu opened this issue Feb 10, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@sukeshpabolu
Copy link

sukeshpabolu commented Feb 10, 2025

Describe the bug

Invalid html in a snippet leads to module has no default export error which is misleading.

In pnpm check and vscode,

<script lang="ts">
  //Box.svelte
  import type { Snippet } from "svelte";

  type Props = {
    children: Snippet
  };

  let { children }: Props = $props();
</script>

{@render children()}
<script>
  //Child.svelte
  import Box from './Box.svelte';
</script>

<Box>
  <div>
    <p>something</p>
    
    <div class="gpc-cont">

  </div>
//div not closed intentionally
</Box>

Reproduction

stackblitz link

run pnpm check

observe logs

Logs

> [email protected] check /home/sukeshpabolu/snippet-ts-bug
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json


====================================
Loading svelte-check in workspace: /home/sukeshpabolu/snippet-ts-bug
Getting Svelte diagnostics...

/home/sukeshpabolu/snippet-ts-bug/src/routes/+page.svelte:2:9
Error: Module '"/home/sukeshpabolu/snippet-ts-bug/src/lib/Child.svelte"' has no default export. (js)
<script>
  import Child from '$lib/Child.svelte';
</script>


====================================
svelte-check found 1 error and 0 warnings in 1 file
 ELIFECYCLE  Command failed with exit code 1.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    svelte: ^5.19.9 => 5.19.9

Severity

annoyance

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github added the bug Something isn't working label Feb 10, 2025
@sukeshpabolu sukeshpabolu changed the title invalid html in a snippet leads to module has no default export error unclosed tag in html in a snippet leads to module has no default export error Feb 11, 2025
@paoloricciuti
Copy link
Member

This should be moved to language-tools as is an issue with svelte2tsx

@sukeshpabolu
Copy link
Author

This should be moved to language-tools as is an issue with svelte2tsx

How can I move this?

@jasonlyu123 jasonlyu123 transferred this issue from sveltejs/svelte Feb 12, 2025
@jasonlyu123
Copy link
Member

jasonlyu123 commented Feb 12, 2025

This is somewhat expected because the way svelte2tsx transform code relies on svelte compiler output. If the svelte compiler throws an error the transformation can't be done. The loose parser mode should be able to handle this. But loose parse is currently only used in the editor not svelte-check and there won't be an error about unclosed tag, which is a problem you do want to catch. Maybe we could keep it this way but just filter out the no-default export error when we know it's a parser error state.

@SukeshP1995
Copy link

I am getting the same no default export error in editor (VScode) too

@jasonlyu123
Copy link
Member

It probably is because you're using a svelte version older than 5.16 or your editor is outdated.

@sukeshpabolu
Copy link
Author

I am using mostly latest version of vscode and extension

Image

Image

[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants