Allow --module bundler --moduleResolution commonjs
#62320
Merged
+181
−241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisite for #62200
This has worked in a coherent way since
--module preserve
was implemented, but was prohibited with a program error.--moduleResolution bundler
(like every other modern TS resolution mode) resolves package.json"exports"
conditions according to the output module syntax being emitted. So in--module commonjs
, imports in .ts and .js files always resolve with the"require"
condition set.This combination of settings is very rarely going to be what people actually want, and is mostly intended as a "my code works, don't bother me" upgrade path for users on
--module commonjs --moduleResolution: node
. (More poignantly, it doesn't seem like deprecating--module commonjs
is an option at this point, and with--moduleResolution node10
going away, that leaves nomoduleResolution
settings left that are legal withcommonjs
.) However, it's also the correct settings for anyone transpiling their code to CommonJS before resolving imports through a bundler. This includes Webpack ts-loader users who have--module commonjs
in their ts-loader tsconfig. However, you should not use this combination of settings just because you set your bundler's output to emit a CommonJS module, so our docs / blog post need to be intentional about highlighting this.