打字稿构建错误TS6305类型声明文件`尚未从源文件构建输出文件

我有一个应用程序项目结构,其中包含单个目录中的所有打字稿源代码src

|- project/
    |- tsconfig.json
    |- tsconfig.node.json
    |- vite.config.ts
    |- src
        |- vite-env.d.ts
        |- main.tsx
        |- App.tsx
        |- manifest.ts
        |- pages
            |- popup.ts
            |- service.ts
        |- utilities
            |- functions.ts

当我尝试构建应用程序(tsc && vite build)时,输出显示错误

error TS6305: Output file '/Users/project/src/utilities/functions.d.ts' has not been built from source file '/Users/project/src/utilities/functions.ts'.
  The file is in the program because:
    Matched by include pattern 'src' in '/Users/project/tsconfig.json'

  tsconfig.json:23:14
    23  "include": ["src"],
                    ~~~~~
    File is matched by include pattern specified here.

src/utilities/functions.ts src/pages/service.ts 导入

root tsconfig.json 文件看起来像这样:

{
    "compilerOptions": {
        "target": "ES2020",
        "useDefineForClassFields": true,
        "lib": ["ES2020", "DOM", "DOM.Iterable"],
        "module": "ESNext",
        "skipLibCheck": true,

        /* Bundler mode */
        "moduleResolution": "bundler",
        "allowImportingTsExtensions": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "react-jsx",

        /* Linting */
        "strict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noFallthroughCasesInSwitch": true
    },
    "include": ["src"],
    "exclude": ["src/**__tests__/*"],
    "references": [{ "path": "./tsconfig.node.json" }]
}

tsconfig.node.json 文件看起来像这样:

{
    "compilerOptions": {
        "composite": true,
        "skipLibCheck": true,
        "module": "ESNext",
        "moduleResolution": "bundler",
        "jsx": "react-jsx",
        "paths": {
            "~src/*": ["./src/*"],
            "~assets/*": ["./src/assets/*"],
            "~pages/*": ["./src/pages/*"],
            "~public/*": ["./src/public/*"]
        },
        "allowSyntheticDefaultImports": true
    },
    "include": ["vite.config.ts", "src", "scripts", "plugins"]
}

有什么想法解决这个问题吗?

0 个回答

  • 2 浏览
  • cheeze 提出于 2024-03-02 07:58:45

相似问题