#Autoimport bug: server/utils not being autoimported

11 messages · Page 1 of 1 (latest)

glass chasm
#

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

graceful berryBOT
#

Hi @glass chasm. 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/**"],
        },
      }
    })
    

    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.

#
  1. 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:

#

@glass chasm Kapa.ai is still learning and improving, please let me know how I did by reacting below.

glass chasm
#

already done all above and still not working

daring berry
#

Autoimports are enabled by default, are you exporting your utilities?

glass chasm
#

yes

#

it only works on top level utilities, if i a subfolders it's not detected

daring berry
#

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

fleet magnet
#

correct