Repository navigation
Description
🔎 Search Terms
content mapper, VirtualFileName, GetEmitModuleFormatOfFile, GetImpliedNodeFormatForEmit, ImpliedNodeFormat, .mts, module commonjs
🕗 Version & Regression Information
- Present on current
main(native Go port) - During load,
filesparsercorrectly setsSourceFileMetaData.ImpliedNodeFormatfromVirtualFileName(e.g.app.box.mts→ ESNext) - But
Program.GetEmitModuleFormatOfFile/GetImpliedNodeFormatForEmitpass the physicalFileName()(e.g.app.box) intoGetImpliedNodeFormatForEmitWorker
⏯ Playground Link
N/A (content mapper / program API)
💻 Code
Content mapper that sets output extension .mts for app.box, with:
{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node10" }, "contentMappers": [{ "package": "mapper", "extensions": [".box"] }] }// app.box (mapped virtual name: app.box.mts)
export const value = 1;Observed via program API after opening a project that loads the mapped file:
mapped.VirtualFileName() == "/home/project/app.box.mts"
meta.ImpliedNodeFormat == ESNext
GetEmitModuleFormatOfFileWorker(VirtualFileName) == ESNext
GetEmitModuleFormatOfFileWorker(FileName) == CommonJS // fallback to options
program.GetEmitModuleFormatOfFile(mapped) == CommonJS // uses FileName
program.GetImpliedNodeFormatForEmit(mapped) == None // uses FileName
Root cause in tsc/internal/compiler/program.go:
func (p *Program) GetEmitModuleFormatOfFile(sourceFile ast.HasFileName) core.ModuleKind {
return ast.GetEmitModuleFormatOfFileWorker(sourceFile.FileName(), ...)
}
func (p *Program) GetImpliedNodeFormatForEmit(sourceFile ast.HasFileName) core.ResolutionMode {
return ast.GetImpliedNodeFormatForEmitWorker(sourceFile.FileName(), ...)
}For non-node16/nodenext emit module kinds, GetImpliedNodeFormatForEmitWorker only keeps ImpliedNodeFormat == ESNext when package.json#type is "module" or the filename ends in .mjs/.mts. The physical .box name fails that gate, so format falls back to compilerOptions.module (CommonJS). The same pattern affects GetModeForUsageLocation / GetEmitSyntaxForUsageLocation.
Note: under module: nodenext the worker returns metadata.ImpliedNodeFormat directly, so the bug is masked there.
🙁 Actual behavior
An ESM-mapped content-mapper file (VirtualFileName *.mts, ImpliedNodeFormat ESNext) reports emit/implied format as CommonJS / None under module: commonjs, so downstream emit/module transformers and format diagnostics see CJS.
🙂 Expected behavior
When VirtualFileName is set, emit/implied format (and usage-location mode helpers) should use it — consistent with load-time metadata derivation in filesparser.go — so *.mts mapped outputs stay ESM under module: commonjs.
Additional information
Same helpers also take FileName() in:
GetModeForUsageLocationGetEmitSyntaxForUsageLocation
Activity
timurzvural commentedon Nov 3, 2026
User-visible impact (with
verbatimModuleSyntax: true+module: commonjs):Content-mapped
app.box→ virtualapp.box.mtsalso gets false diagnostics:exporttreated as CJS under verbatimModuleSyntaximportfrom that file treated as illegal in CJSA physical
app.mtsunder the same options is clean (.mtsforces ESM emit format). So this is not only an API divergence — it surfaces as incorrect verbatimModuleSyntax errors for content-mapped ESM outputs.