typescripttsconfig

TypeScript build error TS6305 type declaration file `Output file has not been built from source file`


I have an application project structure that contains all TypeScript source codes in a single directory 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

When I try to build the application (tsc && vite build), the output shows an error

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 is imported by src/pages/service.ts

The root tsconfig.json file looks like this:

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

The tsconfig.node.json file looks like this:

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

Any idea how to solve this?


Solution

  • There are two files have "include":["src"],you should remove "src" from one of them.