#Component creation / Importation issue

5 messages · Page 1 of 1 (latest)

orchid basalt
#

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

thorn robin
#

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?

orchid basalt
thorn robin
#

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

...
orchid basalt
#

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