Repository navigation
Description
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
tsconfig.json:{ "compilerOptions": { "module": "commonjs", "strict": true }, "files": ["app.ts"] }app.ts:export const app = 1;thing.custom:export const thing: number = 'x';- webpack config:
entry: { main: './app.ts', thing: './thing.custom' }, and one rule{ test: /\.ts$|\.custom$/, loader: 'ts-loader' }with no options. Type checking on (nottranspileOnly). - Build in watch mode: two errors for the one mistake.
- Change
thing.customtoexport const thing: number = 1;. The rebuild still reports TS2322 atthing.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.pendingDiagnosticsholds one entry per file. When the file is compiled,getTypeScriptEmitstores 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 underthing.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
appendTsSuffixTothe two names are the same, so there is one entry. - A
.vuefile's<script lang="ts">through vue-loader, withoutappendTsSuffixTo, is the common way to get here. ts-loader 10 doesn't requireappendTsSuffixTofor such a file any more (toApiFacingFileNameadds.tsby 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
removeCompilationTSLoaderErrorsfinds for a module restored from webpack's persistent cache, which looks entries up bymodule.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
fix: report a file's errors once, on the module that compiled it (#1760)
fix: forget a block its .vue file no longer has (#1763)
fix: keep a real file apart from a file whose made-up name it has (#1764
johnnyreilly commentedon Dec 1, 2026
Fixed on
nextby #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 thething.custom.tsone remained after the file was fixed.Generated by Claude Code