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

问题描述 投票:0回答:1

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

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.tssrc/pages/service.ts

导入

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"]
}

知道如何解决这个问题吗?

typescript tsconfig
1个回答
1
投票

我发现了问题所在 - 这是调用

tsc

出于某种奇怪的原因,我将

tsc
添加到构建命令中。

实际的构建命令是

vite build

换句话说,将构建命令从

tsc && vite build
更改为
vite build
解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.