#srcDir: "src/"
4 messages · Page 1 of 1 (latest)
Hi @devout laurel. 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 information provided in the knowledge sources, it appears that changing the srcDir in your Nuxt configuration can indeed affect auto-imports. Let's address this issue:
-
First, it's important to note that when you set
srcDir: "src/", Nuxt will look for your application files in thesrc/directory instead of the root directory. This includes directories likecomponents/,composables/, andpages/Nuxt Configuration (https://nuxt.com/docs/api/nuxt-config#srcdir). -
Auto-imports in Nuxt are typically set up to scan specific directories, including
components/,composables/, andutils/Directory-based Auto-imports (https://nuxt.com/docs/guide/concepts/auto-imports#directory-based-auto-imports). -
To fix the auto-imports, you need to ensure that these directories are present inside your
src/folder. The structure should look like this:
-| src/
---| components/
---| composables/
---| layouts/
---| middleware/
---| pages/
---| plugins/
---| public/
---| store/
---| app.config.ts
---| app.vue
---| error.vue
- If you've moved your directories but auto-imports are still not working, you might need to configure the
importsoption in yournuxt.config.tsfile. You can specify additional directories to scan for auto-imports Nuxt Configuration - imports (https://nuxt.com/docs/api/nuxt-config#imports):
export default defineNuxtConfig({
srcDir: 'src/',
imports: {
dirs: [
'src/composables',
'src/utils'
// ... any other directories you want to auto-import from
]
}
})
- If you're using custom directories for components, you might also need to update the
componentsconfiguration Custom Directories (https://nuxt.com/docs/guide/directory-structure/components#custom-directories):
export default defineNuxtConfig({
srcDir: 'src/',
components: [
'~/components',
// ... any other component directories
]
})
Remember to restart your Nuxt development server after making these changes to ensure they take effect.