unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.75k stars 486 forks source link

Depend less on auto imports #2232

Open pi0 opened 5 months ago

pi0 commented 5 months ago

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;

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
- [ ] Use explicit imports from their sources in docs (explicit `h3` imports)
- [ ] Update starter template to explicitly import from `nitropack/config`
- [ ] Find a more explicit alternative to `#imports` like `nitro/app` for longer term
- [ ] Investigate solution for pnpm dependency hoisting issues (one solution might be directly adding h3 as dep in starter)
MickL commented 5 months ago

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: https://github.com/unjs/nitro/issues/2305

pi0 commented 5 months ago

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 commented 4 months ago

Hoping to see auto imports disabled in v3 :)

bernhardberger commented 1 month ago

This is gonna be fun down the line rewriting tons of projects and modules. ☠️