MUI 自动导入建议在 VS Code、Next.js 13 项目中不起作用

Kit*_*ten 3 javascript typescript reactjs material-ui next.js

我正在开发一个已安装的Next.js 13项目MUI,但 VS Code 不提供从@mui/material库的自动导入。这如屏幕截图所示。

在此输入图像描述

从其他库自动导入在此文件夹中工作。在其他不基于 的项目中Next js 13,自动导入MUI也可以工作。请告诉我如何解决这个问题?

这是我的tsconfig.json如果有帮助的话:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)

感谢您的关注!

小智 7

看上去很正常啊 但有时在添加新包后需要再次运行 VSCode typescript 引擎。

  1. shift+cmd+p
  2. 选择打字稿重新加载

注意:您必须确保 VSCode 上的文件夹路径正确。如果您在 VSCode 上启动了错误的项目路径,您将无法看到具有自动导入功能的项目包。

另外这个问题不仅仅与MUI有关,也许这个文档可以帮助你。