-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow disabling auto imports #14505
Comments
It was solved for me |
This is a reasonable request, but just to address some of your comments:
You can configure this with
Auto imports can be configured for nitro within
You can use |
In addition to @danielroe's note:
Supported since nuxt/framework#6025 |
I got far with some local changes, but in the end got a build error related to the
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"experimentalDecorators": true,
"paths": {
"~/*": ["./*"],
"@/*": ["./*"]
}
}
}
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
hooks: {
'autoImports:sources': (sources) => sources.splice(0, sources.length),
'autoImports:dirs': (dirs) => dirs.splice(0, dirs.length),
'components:dirs': (dirs) => dirs.splice(0, dirs.length),
},
}
import { defineNuxtPlugin } from 'nuxt'
export default defineNuxtPlugin(() => {
... do something
}) Error:
I also noticed that export { usePinia } from '../node_modules/@pinia/nuxt/dist/runtime/composables';
export { definePageMeta } from '../node_modules/nuxt/dist/pages/runtime/composables';
export { useLink } from 'vue-router'; |
What would be the correct import path for Using Github search, I found a few files which have an import statement: import { defineNuxtPlugin } from '#app' In Pinia, the following import statement is used: import { defineNuxtPlugin } from '#imports' It could be that in the end it boils down to the same, I dont know :) But I could not find a |
Yes, we advise using |
I really think auto-importing is a bad design feature. One of the reasons I dislike RoR. Not knowing explicitly where your code is coming from makes large projects (especially onboarding new devs into projects) extremely hard to reason about. But that's just my opinion. |
You should be able to see where any auto import is coming from by clicking on it in your ide. There are also tools in Nuxt devtools that will show you a bigger overview. |
@danielroe that's just the tip of the iceberg. I'm currently battling how to set up Vitest to work with Nuxt3 (Nuxt tests are barely mentioned, nor how to configure test frameworks to work with auto-imports). I'm also trying to work out how to override the type definitions for a Nuxt3 plugin that's being auto imported. The extra complexity required to get this feature to work is not nearly worth it (IMO). |
I also don't get why we need to alias |
You can use https://github.com/danielroe/nuxt-vitest, where these should all be set up for you. |
I'm using that but it doesn't cover several things eg. Trying to get everything working is a real dance. |
Let me state that I appreciate everything you guys have created here. But as someone who has been a long time user of Vue, there are several design decisions made in Nuxt that are relatively alien to Vue and trying to achieve simplicity (eg. auto-imports) just moves the complexity elsewhere. If someone is using Nuxt they probably also know how to use Vue (which doesn't have auto-importing) so I'm not sure who we're trying to protect with this feature. |
Nuxt's imports design is just abyss of problems. Especially refactoring. You know, move files, rename them, group things. Casual things, but in Nuxt it's incredible pinhead pleasure. 🤌🤌🤌 |
My favorite is naming collision 🤤. This is such an apt retrospect of the 00 years, when all variables were global, and one module in some file affected the work of another. Nice 🙃 |
With big projects. Auto import works like a hell. It should be turned of by default. |
I really don't like the auto import feature either. It should be an opt-in, not an opt-out. At least we should be able to disable it completely, easily. BTW, is there a way to disable the generation of I added this in components: false,
imports: {
autoImport: false,
}, |
I was able to partially disable auto-import. in my case, it was necessary to exclude utils from the general list of auto-imports. To do this, you need to use the imports:dirs hook to remove the element, but not return anything: export default defineNuxtConfig({
hooks: {
'imports:dirs'(dirs) {
const rules = ['utils'];
for (const rule of rules) {
const index = dirs.findIndex((dir) => dir.includes(rule));
dirs.splice(index, 1);
}
}
}
}) |
Describe the feature
First mentioned here by @nikolay-zoteev and @cawa-93 in https://github.com/nuxt/framework/discussions/2271.
I would like to be able to disable auto import, so I can make explicit imports from respective vendor library required in the codebase.
Would become:
Additional, from https://github.com/nuxt/framework/discussions/2271#discussioncomment-2906232:
Additional information
Final checks
The text was updated successfully, but these errors were encountered: