{"record":{"id":"b7838c3d5c204946","repo":"microsoft/TypeScript","slug":"number-of-sourcemap-files-should-be-same-as-js-fil","errorCode":null,"errorMessage":"Number of sourcemap files should be same as js files.","messagePattern":"Number of sourcemap files should be same as js files\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/harness/harnessIO.ts","lineNumber":874,"sourceCode":"                    typeLines += codeLines.slice(lastIndexWritten + 1).join(\"\\r\\n\");\r\n                }\r\n                typeLines += \"\\r\\n\";\r\n                yield [checkDuplicatedFileName(unitName, dupeCase), Utils.removeTestPathPrefixes(typeLines)];\r\n            }\r\n        }\r\n    }\r\n\r\n    export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: compiler.CompilationResult, harnessSettings: TestCaseParser.CompilerSettings): void {\r\n        const declMaps = ts.getAreDeclarationMapsEnabled(options);\r\n        if (options.inlineSourceMap) {\r\n            if (result.maps.size > 0 && !declMaps) {\r\n                throw new Error(\"No sourcemap files should be generated if inlineSourceMaps was set.\");\r\n            }\r\n            return;\r\n        }\r\n        else if (options.sourceMap || declMaps) {\r\n            if (result.maps.size !== ((options.sourceMap ? result.getNumberOfJsFiles(/*includeJson*/ false) : 0) + (declMaps ? result.getNumberOfJsFiles(/*includeJson*/ true) : 0))) {\r\n                throw new Error(\"Number of sourcemap files should be same as js files.\");\r\n            }\r\n\r\n            let sourceMapCode: string | null; // eslint-disable-line no-restricted-syntax\r\n            if ((options.noEmitOnError && result.diagnostics.length !== 0) || result.maps.size === 0) {\r\n                // We need to return null here or the runBaseLine will actually create a empty file.\r\n                // Baselining isn't required here because there is no output.\r\n                sourceMapCode = null; // eslint-disable-line no-restricted-syntax\r\n            }\r\n            else {\r\n                sourceMapCode = \"\";\r\n                result.maps.forEach(sourceMap => {\r\n                    if (sourceMapCode) sourceMapCode += \"\\r\\n\";\r\n                    sourceMapCode += fileOutput(sourceMap, harnessSettings);\r\n                    if (!options.inlineSourceMap) {\r\n                        sourceMapCode += createSourceMapPreviewLink(sourceMap.text, result);\r\n                    }\r\n                });\r\n            }\r","sourceCodeStart":856,"sourceCodeEnd":892,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/harness/harnessIO.ts#L856-L892","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const expected = (options.sourceMap ? result.getNumberOfJsFiles(false) : 0)\n    + (ts.getAreDeclarationMapsEnabled(options) ? result.getNumberOfJsFiles(true) : 0);\nif (result.maps.size !== expected) {\n    throw new Error(`map count ${result.maps.size} != expected ${expected}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm noEmitOnError state matches test intent before expecting maps.","When JSON inputs are present, account for includeJson in the expected count."],"tags":["harness","compiler-output","sourcemap","file-count-mismatch"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}