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

导入CSS模块至TS文件时遇ts(6307)错误求助

导入CSS模块到TS文件时遭遇ts(6307)错误

我在将CSS模块文件导入TS文件时遇到ts(6307)错误,导入其他类型文件无异常。已尝试在tsconfig.src.json中添加./typings.d.ts和**/*.css至include列表,但无论是否添加均报错。

typings.d.ts中已声明*.module.css模块:

declare module '*.module.css' {
  const classes: { [key: string]: string };
  export default classes;
}

完整错误信息:

File '/Users/andy/my-repo/apps/docs/src/left-nav/nav-section.module.css' is not listed within the file list of project '/Users/andy/my-repo/tsconfig.src.json'. Projects must list all files or use an 'include' pattern.ts(6307)

我的tsconfig配置如下:

tsconfig.src.json(错误指向的配置文件)

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "plugins": [{ "name": "typescript-plugin-css-modules" }],
    "types": ["vite/client", "bun-types", "web"]
  },
  "exclude": ["node_modules", "**/node_modules/**/*", "tmp", "**/*.test.ts", "**/*.btest.ts"],
  "include": ["**/*.ts", "**/*.tsx", "./typings.d.ts", "**/*.css"]
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "composite": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "inlineSources": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext",
      "webworker"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "resolveJsonModule": true,
    "rootDir": ".",
    "skipDefaultLibCheck": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "target": "es2016"
  },
  "files": [],
  "references": [
    {
      "path": "./tsconfig.test.json"
    },
    {
      "path": "./tsconfig.src.json"
    }
  ]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 10:33:21