withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.93k stars 2.49k forks source link

astrojs-svelte Unexpected tokens, unavailable stack traces, __vite_ssr_import_2__.TextLine is not a function #12454

Closed djkato closed 3 days ago

djkato commented 6 days ago

Astro Info

Astro                    v4.16.13
Node                     v23.1.0
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind
                         @astrojs/svelte

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

  1. [ERROR] __vite_ssr_import_2__.TextLine is not a function for unknown reason in many of my projects files image
  2. Unexpected tokens instead of ledgible issues / stack traces image The minimal repo I gave tries to reproduce the issue with as little code as possible. I deleted stuff willy nilly, so the code actually might not be correct! But since the issue is astro not reporting the issues right, I think it's fine.

What's the expected result?

To either give proper reasons why something is broken, or just work? I don't see what's wrong in my code.

Link to Minimal Reproducible Example

https://github.com/djkato/astrojs-svelte-error

Participation

ematipico commented 3 days ago

cc @bluwy

bluwy commented 3 days ago
-    import { SelectInline } from "./universal/SelectInline.svelte"
+    import SelectInline from "./universal/SelectInline.svelte"

Svelte components are default exported. I'm not sure why Vite isn't giving nice errors here, I'd suggest reporting an issue to Vite to possibly improve this. Closing this as I don't think it's a bug Astro can fix.

djkato commented 3 days ago

@bluwy IDE Does give me warning about importing it this way. Initially inside my app when I started migrating from svelte 4 to svelte 5, all my imports were the way you suggested. Every single svelte file trying to import a svelte component had error about the imports, which almost all went away when I started importing it the "wrong way". After importing it with {} only like 5 erroring files remained, which had the issues I reported here.

import SelectInline from "./universal/SelectInline.svelte"

Fails right inside the file that tries to import. image

import { SelectInline } from "./universal/SelectInline.svelte"

It starts complaining inside the component, which means it imported correctly, no? image

These errors are still in my repro repo.

bluwy commented 3 days ago

I'm not getting any errors after updating to default imports in the repro. The errors you show seem strange to me and implies some sort of JS parsing error. Maybe you can try re-installing dependencies or use a different package manager? Also, the overrides in your package.json can also be removed.

djkato commented 3 days ago

The package manager was the issue. After I switched from bun to pnpm it builds correctly. I'll go report it there then, thanks for the hint :)