#I can't get the right return type import.meta.glob function
1 messages · Page 1 of 1 (latest)
Hi @stable kayak. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The import.meta.glob function in Astro is a wrapper around Vite's import.meta.glob function. It is used to load many local files into your static site setup. However, it has some limitations and specific behaviors that you should be aware of:
-
import.meta.globonly takes one parameter: a relative URL glob of which local files you'd like to import. It can't take variables or strings that interpolate them, as they aren't statically analyzable. This is becauseimport.meta.globis a wrapper of Vite’simport.meta.globsource (https://docs.astro.build/en/reference/api-reference/#astroglob). -
import.meta.globreturns a map of a file’s path to its content. If you want to load each file immediately, you can useimport.meta.globEager(). Note that this import includes all styles and scripts for any imported files. These will be bundled and added to the page whether or not a file is actually used, as this is decided by static analysis, not at runtime source (https://docs.astro.build/en/reference/api-reference/#astroglob). -
There have been issues reported with the type hints not working correctly with
import.meta.globin certain versions of Astro source (https://github.com/withastro/astro/issues/8552). -
There have also been issues reported with
import.meta.globnot behaving correctly when spaces are included in the prop string source (https://github.com/withastro/astro/issues/5048).