not able to auto import react components from node modules

我们两清 提交于 2019-12-08 16:43:35

I believe I can reproduce the problem you are seeing. Based on my testing, the auto-import functionality built into VS Code only works for symbols defined in files that are already loaded as part of your project because they match, or are directly or indirectly imported by files that match, the include setting in tsconfig.json. (See this thread for some background.)

I started with your configuration files and a blank source file but removed @types/material-ui because it's for the old material-ui package (which you don't have installed) and is just confusing matters. At this point, if I invoke code completion with Ctrl-Space, I am not offered the Material UI components (AppBar, Avatar, ...). But if I add an import, for example import { AppBar } from "@material-ui/core";, that forces the TypeScript server to load @material-ui/core, so now if I invoke code completion again, I am offered the rest of the Material UI components. If you need auto import to work without an existing import, then you could add the appropriate .d.ts files to the include list in tsconfig.json, although then you'd want to use a separate tsconfig.json file for batch compilation so that you don't try to overwrite the JavaScript files in the @material-ui/core package.

I haven't tested any third-party auto-import plugins and can't speak about their behavior.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!