-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Snippet import breaks dev server on first run after npm install #1066
Comments
seems to be essential to trigger the error message, removing it and only using It is related to vites optimizer, starting it with cc @bluwy |
also happens with vps4 / vite5 |
The issue is of snippets being a hidden/special variable in the module script once it's declared in the markup. In Vite's scanner, it takes the content of // Snippet.svelte (what vite's scanner sees as it loosely transpile to JS)
export { foo } // from <script module>
export default {} // emulate default exported component Here's an esbuild playground that illustrates the internal files too. I guess if we want to fix this, we have to kinda regex-search for all |
not sure we have to, as long as you don't use the import in a script block but just reference it in template, it'll be ignored. so if you rename it in the import instead of
|
This works as long as you don't actually need to do something with the snippet in the script block, like pass it to a function, store it in an array, etc. However, I originally ran into this because I want to store the snippet in an object and use it later.
I wouldn't mind dedicating some time to fixing this if I could get some guidance on where to start looking! |
wonder if you can trick it with an indirection foo-reexport.js
not ideal but could unblock you in this situation |
Yep, that works, good idea! In the meanwhile, I did manage to find a different workaround that works for me (I just run the dev server once during the creation of my docker image, and then immediately shut it down -- since the container is only used for local development, it doesn't matter much, and prod builds don't use the dev server anyway), but this is a much cleaner solution. |
Describe the bug
Exporting a snippet from one file, importing it in another file and assigning it to a variable causes the dev server to break on first run after
npm install
.Hopefully this is the right place to report this issue!
Reproduction URL
https://github.com/glupi-borna/svelte-snippet-bug-repro
Reproduction
The reproduction repo is fairly minimal (and has a readme with steps), but to recreate it from scratch:
Create a new project via
npm create vite@latest
(both Svelte+TS and Svelte+JS have this issue).In
src/Snippet.svelte
:In
src/App.svelte
:Now run
npm install
, and thennpm run dev
.The dev server should report an error.
Logs
System Info
The text was updated successfully, but these errors were encountered: