VSCode IntelliSense在Next.js TypeScript项目中导入建议失效
Next.js项目VSCode IntelliSense第三方包导入建议失效问题
使用npx create-next-app创建了基于App Router的Next.js项目,安装了next-auth、axios等第三方包。当前遇到的问题是:VSCode的IntelliSense几乎无法为这些第三方包提供导入建议,但next和react的导入建议正常。手动导入第三方包的函数可正常运行,说明并非缺少类型定义文件,推测是VSCode无法识别或找到对应的声明文件。
项目配置
tsconfig.json
{ "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [ { "name": "next" } ], "paths": { "@/*": ["./*"] } }, "include": [ "next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "tailwind.config.js" ], "exclude": ["node_modules"] }
package.json
{ "name": "course-app", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, "dependencies": { "@hookform/resolvers": "^3.2.0", "@mantine/hooks": "^6.0.19", "@next-auth/prisma-adapter": "^1.0.7", "@prisma/client": "^5.1.1", "@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-alert-dialog": "^1.0.4", "@radix-ui/react-avatar": "^1.0.3", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-dropdown-menu": "^2.0.5", "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-navigation-menu": "^1.1.3", "@radix-ui/react-popover": "^1.0.6", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-scroll-area": "^1.0.4", "@radix-ui/react-select": "^1.2.2", "@radix-ui/react-separator": "^1.0.3", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-switch": "^1.0.3", "@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-toast": "^1.1.4", "@radix-ui/react-tooltip": "^1.0.6", "@tanstack/react-query": "^4.32.6", "axios": "^1.4.0", "bcryptjs": "^2.4.3", "cheerio": "^1.0.0-rc.12", "class-variance-authority": "^0.7.0", "cloudinary": "^1.40.0", "clsx": "^2.0.0", "crisp-sdk-web": "^1.0.21", "date-fns": "^2.30.0", "fastest-levenshtein": "^1.0.16", "gray-matter": "^4.0.3", "lucide-react": "^0.265.0", "mailgun.js": "^9.3.0", "next": "14.0.3", "next-auth": "^4.22.1", "next-cloudinary": "^4.17.1", "next-mdx-remote": "^4.4.1", "next-themes": "^0.2.1", "nodemailer": "^6.9.7", "puppeteer": "^21.5.2", "query-string": "^8.1.0", "react": "18.2.0", "react-dom": "18.2.0", "react-hook-form": "^7.45.4", "react-select": "^5.7.4", "react-share": "^4.4.1", "sharp": "^0.32.6", "stripe": "^14.3.0", "tailwind-merge": "^1.14.0", "tailwindcss-animate": "^1.0.6", "zod": "^3.21.4" }, "devDependencies": { "@faker-js/faker": "^8.0.2", "@types/bcryptjs": "^2.4.6", "@types/node": "^20", "@types/nodemailer": "^6.4.14", "@types/react": "^18", "@types/react-dom": "^18", "autoprefixer": "^10.0.1", "eslint": "^8", "eslint-config-next": "14.0.3", "postcss": "^8", "prettier": "^3.0.3", "prettier-plugin-tailwindcss": "^0.5.6", "prop-types": "^15.8.1", "tailwindcss": "^3.3.0", "typescript": "^5" } }
已尝试的解决方法
- 重新安装并更新包
- 逐个移除包排查兼容性问题
- 创建新项目并安装相同依赖
- 创建不使用App Router的新项目并安装相同依赖
- 使用
yarn重新安装 - 更换不同的
typescript版本 - 降级至Next.js 13
- 移除
tsconfig.json中的includes和excludes字段 - 配置
tsconfig.json指定类型文件路径
复现步骤
克隆指定仓库,使用任意包管理器安装依赖,在app/page.tsx中尝试输入第三方包的函数,查看是否有导入建议。
内容的提问来源于stack exchange,提问作者kmp
相关产品推荐
相关产品推荐

