#[unimport] failed to find "LazyIcon" imported from "#components"
4 messages · Page 1 of 1 (latest)
Hi @elfin thicket. 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:
-
The
@nuxt/iconmodule should handle icons automatically as mentioned in the Nuxt UI documentation, but it seems the testing environment isn't properly resolving these imports. -
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/moduleto yournuxt.config.ts - Create a proper
vitest.config.tsfile - Ensure you're using the Nuxt environment for your tests
- Add
-
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:
- Make sure your Vitest configuration is properly set up:
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
environment: 'nuxt',
// you can optionally set Nuxt-specific environment options
environmentOptions: {
nuxt: {
// your Nuxt config overrides
}
}
}
})
- Ensure you have the proper environment annotation in your test files:
// @vitest-environment nuxt
import { test } from 'vitest'
- For the specific
LazyIconissue, try directly importing the component in your test files:
import { Icon } from '#components'
// or
import { Icon } from '#build/components'
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.