Auto import breaking
I have my type definitions inside shared/types, and my enums are located in shared/types/enums.
When I reference something like FooEnum (from shared/types/enums) inside a type definition in shared/types, it doesn’t auto-import correctly.
If I manually import it, the app’s auto-import system breaks completely.
Any idea how to fix this?
2 Replies
Hi @EatSleepGames. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, I can help you understand the issue with auto-imports in the
shared/ directory.
The problem you're experiencing is a known limitation with Nuxt's auto-import system in the shared/ folder. According to feat(nuxt): add type declarations for shared auto-imports, shared utilities are globally auto-imported but were not being recognized within the same shared directory by TypeScript/editors.
The issue describes exactly your scenario:
The solution implemented in Nuxt addresses this by creating a dedicated TypeScript declaration file (types/shared.d.ts) that makes shared auto-imports available within the shared directory itself.
However, there are a few important things to note:
1. Compatibility Version Required: According to docs: add auto import info about shared utils, auto-import functionality for shared/utils/ and shared/types/ directories is only active when compatibilityVersion: 4 is enabled in your Nuxt configuration.
2. Manual imports breaking auto-imports: If manually importing causes the entire auto-import system to break, this suggests there might be a configuration issue or you may need to ensure you're using the correct Nuxt version with the fixes applied.
To fix your issue:
1. Ensure you have compatibilityVersion: 4 enabled in your nuxt.config.ts
2. Make sure you're using a recent version of Nuxt that includes the shared directory auto-import fixes
3. Avoid manually importing within the shared/ directory - the auto-imports should work automatically once properly configured
If the issue persists, it may be related to the specific version of Nuxt you're using, as several fixes for shared directory type handling were implemented in recent pull requests.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@140278910406361088> Kapa.ai is still learning and improving, please let me know how I did by reacting below.