Hello, I have a problem when creating a component in the components folder. When I create the file I do it in the following way: MyComponent.astro the problem is that when I want to do an import it does not recognize the code, it remains blank and does not allow me to use the imported element. How can I solve that? I am using the official Astro extension for language support. Thank you
#Component creation / Importation issue
5 messages · Page 1 of 1 (latest)
How are you importing your component? You'll import like
---
import MyComponent from './components/MyComponent.astro'
---
<MyComponent />
Other than that, are you getting any errors or anything?
Hi Jumper, this is how I import my components. In my case it is an icon that I want to import, I leave you a reference image so you can see that I use the same syntax.
Ah so just make sure that your imports are within your "fenceposts" or your Frontmatter. Basically just the --- at the top of the file.
// AsideMenu.astro
--- <-- These guys
import LibraryIcon from '../icons/Library.astro'
--- <-- right here
...
OMG! I am very grateful for your help, I tried it and it was indeed the solution, I am learning Astro on my first day at work and I really didn't know that solution, thank you very much! I'll be more careful next time