You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NX Monorepo中Next.js共享库VSCode自动导入功能失效求助

NX Monorepo(Next.js+TypeScript)VSCode自动导入共享库组件失效问题
  • 搭建了基于Next.js+TypeScript的NX Monorepo,使用版本"@nx/next": "16.5.1"。共享库中的组件可通过手动编写导入语句(如import { Typography } from '@frontend/jsx-core';)在主应用中正常使用,但VSCode的自动导入功能无法给出导入提示。
  • 手头有一个使用"@nrwl/next": "15.6.3"的旧项目,自动导入功能正常,但新建同版本的项目仍存在相同问题。已对比新旧项目配置文件并尝试复制配置,问题未解决。
  • 补充说明:手动导入某个共享组件后,再添加同库的其他组件时,自动导入功能可正常工作,且会提示更新已有导入语句。

相关tsconfig配置

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@frontend/jsx-core": ["libs/jsx-core/src/index.ts"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

应用目录下的tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "jsx": "preserve",
    "allowJs": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "types": ["jest", "node"]
  },
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "**/*.js",
    "**/*.jsx",
    "../../apps/platform/.next/types/**/*.ts",
    "../../dist/apps/platform/.next/types/**/*.ts",
    "next-env.d.ts"
  ],
  "exclude": [
    "node_modules",
    "jest.config.ts",
    "src/**/*.spec.ts",
    "src/**/*.test.ts"
  ]
}

tsconfig.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["jest", "node"],
    "jsx": "react"
  },
  "include": [
    "jest.config.ts",
    "src/**/*.test.ts",
    "src/**/*.spec.ts",
    "src/**/*.test.tsx",
    "src/**/*.spec.tsx",
    "src/**/*.test.js",
    "src/**/*.spec.js",
    "src/**/*.test.jsx",
    "src/**/*.spec.jsx",
    "src/**/*.d.ts"
  ]
}

内容的提问来源于stack exchange,提问作者Rowin_nb2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 13:55:24