unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.27k stars 199 forks source link

Plugin treats class method as function call and try import not required deps #499

Open KawaiiZapic opened 5 months ago

KawaiiZapic commented 5 months ago

Describe the bug

if a class include a method that has same name in a present, this plugin will try to inject import statement into this file.
This is ok in common because we only want to import it when we installed it as project deps, but plugin will inject import statement into other repo in monorepo without the dep, and will cause error "dep not found".

In the reproduction, run npm run build, vite will exit with error. If rename inject to inject2, build can be done.

Reproduction

https://stackblitz.com/edit/vitejs-vite-tdqwze?file=src%2Fmain.ts&view=editor

System Info

Not provided

Used Package Manager

npm

Validations

stackblitz[bot] commented 5 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.