Skip to content

v10: a file without a TypeScript extension and without appendTsSuffixTo has its errors reported twice, and one copy stays after the error is fixed #1745

Done

Description

@johnnyreilly

Raised in the review of #1743, where it was seen for a .vue file's script. It is not about Vue: it is on next (c78033c) for any file ts-loader compiles that has no TypeScript extension and isn't matched by appendTsSuffixTo. Reproduced on next.

Expected Behaviour

A type error in such a file is reported once, and stops being reported when it is fixed.

Actual Behaviour

The error is reported twice, under two names: the file's own (thing.custom) and the name ts-loader gives TypeScript for it (thing.custom.ts). When the error is fixed, the first copy goes and the second stays, so the build keeps failing on an error that is no longer in the file.

Watch mode on next, webpack 5, Node 22, Linux:

Build Change Errors reported
0 first build; thing.custom has a type error TS2322 at thing.custom(1,14) and TS2322 at thing.custom.ts(1,14)
1 edit app.ts (unrelated) both again
2 edit thing.custom, error still there both again
3 fix the error in thing.custom TS2322 at thing.custom.ts(1,14)

With appendTsSuffixTo: [/\.custom$/] the same run reports the error once in builds 0 to 2 and nothing in build 3.

Steps to Reproduce the Problem

  1. tsconfig.json: { "compilerOptions": { "module": "commonjs", "strict": true }, "files": ["app.ts"] }
  2. app.ts: export const app = 1;
  3. thing.custom: export const thing: number = 'x';
  4. webpack config: entry: { main: './app.ts', thing: './thing.custom' }, and one rule { test: /\.ts$|\.custom$/, loader: 'ts-loader' } with no options. Type checking on (not transpileOnly).
  5. Build in watch mode: two errors for the one mistake.
  6. Change thing.custom to export const thing: number = 1;. The rebuild still reports TS2322 at thing.custom.ts(1,14).

Location of a Minimal Repository that Demonstrates the Issue.

None. The steps above were run with a script that drives webpack(config).watch(...); I can turn them into a comparison test.

Notes

  • Likely cause, from reading the code, not confirmed by a fix: instance.pendingDiagnostics holds one entry per file. When the file is compiled, getTypeScriptEmit stores its errors under the key of the name webpack knows (thing.custom). The end-of-build recheck works with the names TypeScript knows, so it looks for an entry under thing.custom.ts, finds none, takes the file as never checked, and stores a second entry under that key. Later compiles only replace the first entry. The second is only replaced when the recheck checks the file again, which a change to the file itself doesn't cause.
  • With appendTsSuffixTo the two names are the same, so there is one entry.
  • A .vue file's <script lang="ts"> through vue-loader, without appendTsSuffixTo, is the common way to get here. ts-loader 10 doesn't require appendTsSuffixTo for such a file any more (toApiFacingFileName adds .ts by itself), so this is easy to hit.
  • The fix suggested in the review: store the compile's entry under the TypeScript name too, and keep the file's own name only for display. That changes what removeCompilationTSLoaderErrors finds for a module restored from webpack's persistent cache, which looks entries up by module.resource, so it wants a persistent-cache test with such a file.
  • fix: keep a Vue file's script and template apart #1743 keys a Vue block's entry by the TypeScript name already; the script's entry is left as it is there.

Activity

  1. added 3 commits that reference this issue on Dec 1, 2026
    4519f74
    123a5f8
    1cc1ac3
  2. johnnyreilly commented on Dec 1, 2026

    @johnnyreilly
    MemberAuthor

    Fixed on next by #1760 (4519f74), listed under 10.0.0-beta.2 in the changelog.

    The cause: ts-loader stored a compiled file's errors under webpack's name for the file (thing.custom), and the end-of-build recheck works from TypeScript's names (thing.custom.ts). The recheck found no entry, took the file as never checked, and reported its errors a second time under that name. That copy was on no module, so it stayed after the file was fixed.

    #1760 keys the stored errors by TypeScript's name for the file, and each entry carries the resource of the webpack module that compiled it. The errors are reported once, on that module, and go when the file is fixed.

    Test: noTsExtensionErrorsWatch. Before the fix it reported two errors, and the thing.custom.ts one remained after the file was fixed.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions