TSConfig
customConditions
--customConditions
takes a list of additional conditions that should succeed when TypeScript resolves from an exports
or imports
field of a package.json
.
These conditions are added to whatever existing conditions a resolver will use by default.
For example, when this field is set in a tsconfig.json
as so:
jsonc
{"compilerOptions": {"target": "es2022","moduleResolution": "bundler","customConditions": ["my-condition"]}}
Any time an exports
or imports
field is referenced in package.json
, TypeScript will consider conditions called my-condition
.
So when importing from a package with the following package.json
jsonc
{// ..."exports": {".": {"my-condition": "./foo.mjs","node": "./bar.mjs","import": "./baz.mjs","require": "./biz.mjs"}}}
TypeScript will try to look for files corresponding to foo.mjs
.
This field is only valid under the node16
, nodenext
, and bundler
options for --moduleResolution
.