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: import.meta.env crashes app if meta prop exists #14234

Closed
kyoshino opened this issue Nov 9, 2024 · 4 comments · Fixed by #14286
Closed

Svelte 5: import.meta.env crashes app if meta prop exists #14234

kyoshino opened this issue Nov 9, 2024 · 4 comments · Fixed by #14286
Labels

Comments

@kyoshino
Copy link
Contributor

kyoshino commented Nov 9, 2024

Describe the bug

In Svelte 5, using import.meta.env crashes the application if there is a prop named meta in the component. The same issue happens with import.meta.glob.

Firefox says: Uncaught (in promise) TypeError: import.meta is not a function
Chrome says: Uncaught (in promise) TypeError: (intermediate value) is not a function

When this error happens, my SvelteKit site shows a blank page.

Reproduction

REPL: v4.2.19 / v5.1.13

This is a minimum version of my <MetaTags> component. With Svelte 4, REPL says just undefined but that’s fine, my code has no error. But with Svelte 5, this no longer works. I need to rename the prop. Uncommenting export let meta = {}; removes the error, saying undefined like Svelte 4.

Logs

No response

System Info

-

Severity

blocking an upgrade

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Nov 9, 2024

I found the cause of the error; Svelte's compiler uses is-reference, a package that is used for the AST to find nodes that are references (eg variables, like foo in let foo = 0, but not foo in bar.foo). However, this package does not work for MetaProperty nodes, which are what are parsed from import.meta.*. I've created an issue and now a pull request in the repository because of this, thanks for the bug report!

@kyoshino kyoshino changed the title Svelte 5: import.meta.env crashes if meta prop exists Svelte 5: import.meta.env crashes app if meta prop exists Nov 9, 2024
@dummdidumm dummdidumm added the bug label Nov 9, 2024
@Ocean-OS
Copy link
Contributor

This issue has been resolved, could someone please close it?

@dummdidumm
Copy link
Member

Technically it's not fully closed yet because to be sure everyone gets the update we gotta bump the dependency

@kyoshino
Copy link
Contributor Author

Updated is-reference locally and the site no longer crashes. Thanks for the fix, @Ocean-OS!

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

Successfully merging a pull request may close this issue.

3 participants