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

import.meta.glob works in script but breaks in template #7671

Closed
janosh opened this issue Nov 16, 2022 · 1 comment
Closed

import.meta.glob works in script but breaks in template #7671

janosh opened this issue Nov 16, 2022 · 1 comment
Labels

Comments

@janosh
Copy link
Contributor

janosh commented Nov 16, 2022

Describe the bug

The following errors

<script>
  console.log(import.meta.glob(`./*`))  // works
</script>

<!-- breaks -->
{import.meta.glob(`./*`)}

[plugin:vite:import-glob] Invalid glob import syntax: Expect CallExpression, got BinaryExpression

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-khnpjr?file=src%2Froutes%2F%2Blayout.svelte&terminal=devr

Logs

No response

System Info

StackBlitz

Severity

annoyance

Additional Information

No response

@gtm-nayan
Copy link
Contributor

I'd say this is a Vite bug because instead of transforming and replacing just the import.meta.glob('./*') part with an object, it's looking at the whole expression generated by Svelte to coerce the object to a string.

You can file an issue upstream with a simplified repro without SvelteKit and as a workaround, you can use a comma operator like {(0,import.meta.glob("./*"))} to force svelte to include the parens and get Vite to parse the glob import in isolation.

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

No branches or pull requests

2 participants