Skip to content
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

Depend less on auto imports #2232

Open
4 tasks
pi0 opened this issue Mar 8, 2024 · 3 comments
Open
4 tasks

Depend less on auto imports #2232

pi0 opened this issue Mar 8, 2024 · 3 comments
Labels
discussion documentation Improvements or additions to documentation

Comments

@pi0
Copy link
Member

pi0 commented Mar 8, 2024

The history of auto import idea probably backs to Nuxt Components (an amazing initiative by @kevinmarrec) and then same time as Nuxt 3 development, thanks to @antfu, we adopted unimport.

Auto imports make the DX of writing any javascript code much more minimalistic by automatically injecting necessary import statements in the modules that need them which means full tree-shaking same as manually importing them.

However, over time, it also showed negative effects;

  • When reading sources or docs it is less understandable without knowing the sources of all auto imports
  • IDE support is still not perfect, we need a prepare step to generate the types, and even after that, click to jump does not always go to the source, it goes to the intermediate file,
  • Some users/frameworks prefer explicitly over magical conventions.
  • To save process cost, we skip auto imports for node_modules, and it implies module authors take additional care of explicitly importing from #imports virtual module.

I still love auto imports and like the ability to have them but also think we could depend less on them and keep it for advanced usage and users who already know what they are doing.

For Nitro 2.x auto import feature shall remain enabled an I think for the sake of backward compatibility, in Nitro 3.x, we might keep having #imports but deprecated. We might also think about making the auto import experience opt-in for direct nitro users. (subject to discussion, only an idea for now)

Tasks

@MickL
Copy link
Contributor

MickL commented Mar 24, 2024

I wrote it already in some Nuxt issues but I would love auto imports being fully disabled by default + all the docs updated for the reasons you stated. Personally I see no benefits of having auto imports, but a lots of downsides.

Right now it is not clear to developers what actually comes from H3, what from Nitro, what from Nuxt and what from Vue.

I failed multiple times disabling auto imports within a Nuxt app as well as in a Nitro app: #2305

@pi0
Copy link
Member Author

pi0 commented Mar 25, 2024

Thanks for your feedback @MickL. This decision for Nuxt should happen within a Nuxt-related discussion. We might consider disabling it by default for Nitro core but probably in 1-2 more next major versions progressively.

@MickL
Copy link
Contributor

MickL commented Apr 4, 2024

Hoping to see auto imports disabled in v3 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants