N
Nuxt19h ago
DaVidaLoca

vs-code and auto-imports

Hi, I'm having an issue with my IDE — it doesn't detect the utils function inside my utils folder, even though the code runs fine. Am I missing a VSCode configuration or something
No description
No description
2 Replies
kapa.ai
kapa.ai19h ago
Hi @DaVidaLoca. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- If your code runs fine but VS Code doesn't detect or auto-import your utility functions from the utils folder, it's likely related to TypeScript type generation or the way Nuxt auto-imports are set up. Key points to check: 1. Type Generation:
Nuxt auto-generates type declarations for auto-imported utilities in .nuxt/imports.d.ts. For VS Code to recognize these, you need to have the Nuxt dev server running, or run nuxi prepare, nuxt dev, or nuxt build to generate/update the types. If you create or modify utility functions without the dev server running, TypeScript (and thus VS Code) may not recognize them until the types are regenerated.
See more in the Nuxt docs and auto-imports concept. 2. File Location and Scanning:
By default, Nuxt only auto-imports files at the top level of the utils/ directory. If your utility is in a subfolder, it won't be auto-imported unless you re-export it in utils/index.ts or configure the imports.dirs option in your nuxt.config.ts to include nested directories.
See directory scanning details. 3. VS Code Configuration:
No special VS Code configuration is required beyond ensuring that your project’s type declarations are up to date. If you have recently added new utilities, restart VS Code or reload the TypeScript server to pick up new types. Example: Re-exporting for auto-imports
// utils/index.ts
export { myUtil } from './subfolder/myUtil'
// utils/index.ts
export { myUtil } from './subfolder/myUtil'
Or, configure nuxt.config.ts:
export default defineNuxtConfig({
imports: {
dirs: [
'utils/**'
]
}
})
export default defineNuxtConfig({
imports: {
dirs: [
'utils/**'
]
}
})
See more on configuring auto-imports. Summary:
Make sure your utilities are at the top level of utils/ or properly re-exported/configured, and that your type declarations are up to date by running the Nuxt dev server or nuxi prepare. This should resolve VS Code not detecting your utility functions for auto-imports. If you follow these steps and still have issues, please provide more details about your folder structure and the specific utility function in question. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai19h ago
<@457564307434242069> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?