Autoimport bug: server/utils not being autoimported

Hello there!, i recently noticed some changes on my nuxt project. My app relies heavily on autoimports from server/utils, but i noticed it's not getting automatically created anymore!. The docs aren't completely clear about this change, and i'm worried for the state of the application. I tried several solutions, updating nuxt3 to the latest version, adding the utils dir to the nuxtconfig file, but none has been successful. I tried generating a new nuxt3 project, and noticed this isn't particular to my original app, the server/utils do not get auto imported anymore. Can anyone give me insight about this change? if i need to change or add some configuration to be able to generate automatically the autoimports i need? Thank you
7 Replies
kapa.ai
kapa.ai4w ago
Hi @Mariana Zapata. 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 provided, it appears there have been some recent changes and discussions regarding auto-imports in Nuxt 3, particularly for the server/utils directory. Let me summarize the relevant information and provide some insights: 1. Recent Change: There was a recent issue reported and fixed regarding auto-imports not working for the Nitro server. This was addressed in GitHub Issue #30098. 2. Current Behavior: According to the Nuxt documentation on utils, only server/utils are auto-imported in the server/ directory. This suggests that the auto-import functionality for server/utils should still be working. 3. Possible Solution: If you're experiencing issues with auto-imports not working for server/utils, you can try adding the following configuration to your nuxt.config.ts file:
export default defineNuxtConfig({
nitro: {
imports: {
dirs: ["server/utils/**"],
},
}
})

export default defineNuxtConfig({
nitro: {
imports: {
dirs: ["server/utils/**"],
},
}
})

This configuration explicitly tells Nitro to import from the server/utils directory and its subdirectories. 4. Version Compatibility: Make sure you're using the latest version of Nuxt 3, as some issues might have been resolved in recent updates. 5. Scanning Behavior: If you've disabled auto-imports or changed the scanning behavior, this could affect the auto-import functionality. Check your nuxt.config.ts file to ensure you haven't set imports.autoImport to false or imports.scan to false as mentioned in the Nuxt documentation. 6. Nested Directories: Be aware that auto-imports might not work for deeply nested directories within server/utils. Try to keep your utility functions at the root of the server/utils directory. If you're still experiencing issues after trying these solutions, it might be worth creating a minimal reproduction of the problem and reporting it on the Nuxt GitHub repository for further investigation. GitHub Issue #30098 and Nuxt Documentation on Utils provide more context on this topic. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@1030106341672484984> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mariana Zapata
Mariana ZapataOP4w ago
already done all above and still not working
bryce
bryce4w ago
Autoimports are enabled by default, are you exporting your utilities?
Mariana Zapata
Mariana ZapataOP3w ago
yes it only works on top level utilities, if i a subfolders it's not detected
bryce
bryce3w ago
I don't think subdirectories are imported by default (source) You can add more directories to the import.dirs list in your nuxt.config file

Did you find this page helpful?