isolatedModules
acts like moduleDetection: "force"
#54094
Labels
Milestone
isolatedModules
acts like moduleDetection: "force"
#54094
Bug Report
With TypeScript 5.0, issue #46295 was addressed by @andrewbranch and the compiler no longer considers it a build error to have a global script in a project with
isolatedModules: true
.However, I was surprised that
isolatedModules: true
still forces all scripts to emit in module format.This can be seen in the TypeScript Playground. The following example emits an AMD module, even though the script contents do not contain
export
/import
andmoduleDetection
was set to auto.https://www.typescriptlang.org/play?module=2&moduleDetection=2&isolatedModules=true&ssl=4&ssc=29&pln=1&pc=1#code/PTAEAEFsHsBMFcA2BTAXAQ0rAUCCMEUARZAF2QGNSBLaAOw3lOlzHGoGdpF1zYBZOEmQdUpAE7xk2CvS4oAdImgBzABQAiABLJEy0AHdo4xLACEGgJQBuIA
I expected to be able to control the module emit via
moduleDetection
. I didn't expectisolatedModules: true
to act likemoduleDetection: "force"
.The use case I was hoping to implement was setting
isolatedModules: "true"
on a project that is mostly modules, but has a "bootstrap" script that is a non-module, and usetranspileModule
to emit. I found that the bootstrap script emitted as a module, which failed to work at runtime.If
transpileModule
can't safely emit global scripts, and there is not interest in supporting such emit, it might be more intuitive if settingisolatedModules: true
also demanded thatmoduleDetection: "force"
be explicitly set.If
transpileModule
can safely emit global scripts, ideallyisolatedModules: true
would stop forcing module emit, leaving the decision tomoduleDetection
.🕗 Version & Regression Information
This changed between versions 4.9 and 5.0. (Or rather, the new behavior in 5.0 makes this behavior apparent. Before it didn't matter that
isolatedModules
forced module format emit, because it also rejected non-modules outright.)🙁 Actual behavior
From the playground link above,
🙂 Expected behavior
Expected no AMD module wrapper:
The text was updated successfully, but these errors were encountered: