microsoft/TypeScript · error · Error
Number of sourcemap files should be same as js files.
Error message
Number of sourcemap files should be same as js files.
What it means
Thrown by doSourcemapBaseline when inlineSourceMap is false, sourceMap and/or declaration maps are enabled, and the number of generated map files (result.maps.size) does not equal the expected count: JS-file count (if sourceMap) plus JS+JSON-file count (if declaration maps). The harness enforces a one-map-per-output invariant for external sourcemaps.
Source
Thrown at src/harness/harnessIO.ts:874
typeLines += codeLines.slice(lastIndexWritten + 1).join("\r\n");
}
typeLines += "\r\n";
yield [checkDuplicatedFileName(unitName, dupeCase), Utils.removeTestPathPrefixes(typeLines)];
}
}
}
export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: compiler.CompilationResult, harnessSettings: TestCaseParser.CompilerSettings): void {
const declMaps = ts.getAreDeclarationMapsEnabled(options);
if (options.inlineSourceMap) {
if (result.maps.size > 0 && !declMaps) {
throw new Error("No sourcemap files should be generated if inlineSourceMaps was set.");
}
return;
}
else if (options.sourceMap || declMaps) {
if (result.maps.size !== ((options.sourceMap ? result.getNumberOfJsFiles(/*includeJson*/ false) : 0) + (declMaps ? result.getNumberOfJsFiles(/*includeJson*/ true) : 0))) {
throw new Error("Number of sourcemap files should be same as js files.");
}
let sourceMapCode: string | null; // eslint-disable-line no-restricted-syntax
if ((options.noEmitOnError && result.diagnostics.length !== 0) || result.maps.size === 0) {
// We need to return null here or the runBaseLine will actually create a empty file.
// Baselining isn't required here because there is no output.
sourceMapCode = null; // eslint-disable-line no-restricted-syntax
}
else {
sourceMapCode = "";
result.maps.forEach(sourceMap => {
if (sourceMapCode) sourceMapCode += "\r\n";
sourceMapCode += fileOutput(sourceMap, harnessSettings);
if (!options.inlineSourceMap) {
sourceMapCode += createSourceMapPreviewLink(sourceMap.text, result);
}
});
}
View on GitHub (pinned to b465fdbfe1)
Solutions
- Compare result.maps.size against the expected count formula in the message context; list result.maps and result.js to find the mismatched file.
- If noEmitOnError and diagnostics are present, maps may legitimately be absent — confirm the diagnostic state matches test expectations.
- If a compiler change altered map granularity, update the test or the harness invariant accordingly.
Defensive patterns
Strategy: validation
Validate before calling
const expected = (options.sourceMap ? result.getNumberOfJsFiles(false) : 0)
+ (ts.getAreDeclarationMapsEnabled(options) ? result.getNumberOfJsFiles(true) : 0);
if (result.maps.size !== expected) {
throw new Error(`map count ${result.maps.size} != expected ${expected}`);
} Prevention
- Confirm noEmitOnError state matches test intent before expecting maps.
- When JSON inputs are present, account for includeJson in the expected count.
When it happens
Trigger: A test enables external sourcemaps (sourceMap:true and/or declaration maps) and the compilation produces a different number of .map files than output files. The expected count is (sourceMap ? getNumberOfJsFiles(false) : 0) + (declMaps ? getNumberOfJsFiles(true) : 0).
Common situations: A compiler change that merges/splits sourcemap files, a noEmitOnError path that suppresses some maps, a transform that drops maps, or a test with inputs that emit JS but no map. Also triggered when JSON inputs affect the count via includeJson.
Related errors
- There were no errors and declFiles generated did not match n
- No sourcemap files should be generated if inlineSourceMaps w
- Only declaration files should be generated when emitDeclarat
- Cannot have undefined value for compiler option '${name}'.
- Unknown value '${value}' for compiler option '${name}'.
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/b7838c3d5c204946.
Report an issue: GitHub.