[unimport] failed to find "LazyIcon" imported from "#components"
Hello !
I'm having an issue when running tests on my Nuxt module. I’ve registered the
@nuxt/icon
module, but when I run my tests (with vitest
), I get the following error:
2 Replies
Hi @Necrelox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I understand you're encountering an error with the
LazyIcon
component from @nuxt/icon
when running tests with Vitest. This is related to auto-imports in Nuxt not working correctly during testing.
Based on the knowledge sources, there are a few things to consider:
1. The @nuxt/icon
module should handle icons automatically as mentioned in the Nuxt UI documentation, but it seems the testing environment isn't properly resolving these imports.
2. For Vitest testing with Nuxt, you need to set up the proper environment. According to the Nuxt testing documentation, you should:
- Add @nuxt/test-utils/module
to your nuxt.config.ts
- Create a proper vitest.config.ts
file
- Ensure you're using the Nuxt environment for your tests
3. For the specific error with components not being found, you might need to directly import the component instead of relying on auto-imports during tests.
Here's what you can try:
1. Make sure your Vitest configuration is properly set up:
2. Ensure you have the proper environment annotation in your test files:
3. For the specific LazyIcon
issue, try directly importing the component in your test files:
If you're still facing issues, it might be related to how the components are being registered during testing. According to a Stack Overflow post, sometimes removing explicit imports and relying on auto-imports can help with modules like nuxt-svgo
, which might also apply to @nuxt/icon
.
Remember that the Nuxt testing environment needs to properly initialize all the modules and auto-imports, which can sometimes be tricky with third-party modules.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@295266220444352512> Kapa.ai is still learning and improving, please let me know how I did by reacting below.