diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e0e6f0077a976..843a5508bf706 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5558,6 +5558,22 @@ "category": "Message", "code": 6412 }, + "Entering conditional exports.": { + "category": "Message", + "code": 6413 + }, + "Resolved under condition '{0}'.": { + "category": "Message", + "code": 6414 + }, + "Failed to resolve under condition '{0}'.": { + "category": "Message", + "code": 6415 + }, + "Exiting conditional exports.": { + "category": "Message", + "code": 6416 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 8263abea028ad..e042cf6512b0f 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2584,19 +2584,26 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo } else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null if (!Array.isArray(target)) { + traceIfEnabled(state, Diagnostics.Entering_conditional_exports); for (const condition of getOwnKeys(target as MapLike)) { if (condition === "default" || state.conditions.indexOf(condition) >= 0 || isApplicableVersionedTypesKey(state.conditions, condition)) { traceIfEnabled(state, Diagnostics.Matched_0_condition_1, isImports ? "imports" : "exports", condition); const subTarget = (target as MapLike)[condition]; const result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern, key); if (result) { + traceIfEnabled(state, Diagnostics.Resolved_under_condition_0, condition); + traceIfEnabled(state, Diagnostics.Exiting_conditional_exports); return result; } + else { + traceIfEnabled(state, Diagnostics.Failed_to_resolve_under_condition_0, condition); + } } else { traceIfEnabled(state, Diagnostics.Saw_non_matching_condition_0, condition); } } + traceIfEnabled(state, Diagnostics.Exiting_conditional_exports); return undefined; } else { diff --git a/tests/baselines/reference/bundlerNodeModules1.trace.json b/tests/baselines/reference/bundlerNodeModules1.trace.json index b8728c149e960..2d60a6f2765f4 100644 --- a/tests/baselines/reference/bundlerNodeModules1.trace.json +++ b/tests/baselines/reference/bundlerNodeModules1.trace.json @@ -4,12 +4,15 @@ "File '/package.json' does not exist.", "Loading module 'dual' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/dual/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.js'.", "File name '/node_modules/dual/index.js' has a '.js' extension - stripping it.", "File '/node_modules/dual/index.ts' does not exist.", "File '/node_modules/dual/index.tsx' does not exist.", "File '/node_modules/dual/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/dual/index.d.ts', result '/node_modules/dual/index.d.ts'.", "======== Module name 'dual' was successfully resolved to '/node_modules/dual/index.d.ts' with Package ID 'dual/index.d.ts@1.0.0'. ========", "======== Resolving module 'dual' from '/main.mts'. ========", diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json new file mode 100644 index 0000000000000..4082b9545e345 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json @@ -0,0 +1,22 @@ +[ + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Bundler'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json new file mode 100644 index 0000000000000..f99d7a4fa0516 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json @@ -0,0 +1,39 @@ +[ + "File '/node_modules/dep/dist/package.json' does not exist.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Node16'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "File '/node_modules/dep/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========", + "File 'package.json' does not exist.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups." +] \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json new file mode 100644 index 0000000000000..4c63ea4889b66 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json @@ -0,0 +1,39 @@ +[ + "File '/node_modules/dep/dist/package.json' does not exist.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'NodeNext'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "File '/node_modules/dep/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========", + "File 'package.json' does not exist.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups." +] \ No newline at end of file diff --git a/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json b/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json index 5b02129d63960..48028b7f755d7 100644 --- a/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json +++ b/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json @@ -4,6 +4,7 @@ "File '/package.json' does not exist.", "Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/lodash/package.json'.", + "Entering conditional exports.", "Saw non-matching condition 'browser'.", "Matched 'exports' condition 'webpack'.", "Using 'exports' subpath '.' with target './webpack.js'.", @@ -11,6 +12,8 @@ "File '/node_modules/lodash/webpack.ts' does not exist.", "File '/node_modules/lodash/webpack.tsx' does not exist.", "File '/node_modules/lodash/webpack.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'webpack'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/lodash/webpack.d.ts', result '/node_modules/lodash/webpack.d.ts'.", "======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/webpack.d.ts' with Package ID 'lodash/webpack.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json index a4d5f1584f99d..2de6e35148566 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json @@ -39,9 +39,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.cts'. ========", @@ -50,9 +53,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.cts'. ========", @@ -61,11 +67,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.cts'. ========", @@ -126,9 +136,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.mts'. ========", @@ -137,9 +150,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.mts'. ========", @@ -148,11 +164,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json index c3b4275e49cd0..6f42ddd75ee24 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json @@ -39,9 +39,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.cts'. ========", @@ -50,9 +53,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.cts'. ========", @@ -61,11 +67,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.cts'. ========", @@ -126,9 +136,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.mts'. ========", @@ -137,9 +150,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.mts'. ========", @@ -148,11 +164,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json index 86b684ebdf505..2a50df0adeead 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json @@ -4,18 +4,24 @@ "File '/package.json' does not exist.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mts' does not exist.", "File '/node_modules/foo/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/@types/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", @@ -34,19 +40,27 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mts' does not exist.", "File '/node_modules/bar/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "Found 'package.json' at '/node_modules/@types/bar/package.json'.", + "Entering conditional exports.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json index 9312334354570..9c99e7dbe3ac8 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json @@ -7,17 +7,23 @@ "File '/package.json' does not exist.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mts' does not exist.", "File '/node_modules/foo/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", @@ -34,19 +40,27 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mts' does not exist.", "File '/node_modules/bar/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", diff --git a/tests/baselines/reference/selfNameModuleAugmentation.trace.json b/tests/baselines/reference/selfNameModuleAugmentation.trace.json index f9b4d54f55df1..fa0232b7c6ebf 100644 --- a/tests/baselines/reference/selfNameModuleAugmentation.trace.json +++ b/tests/baselines/reference/selfNameModuleAugmentation.trace.json @@ -3,11 +3,13 @@ "Explicitly specified module resolution kind: 'Bundler'.", "File '/node_modules/acorn-walk/dist/package.json' does not exist.", "Found 'package.json' at '/node_modules/acorn-walk/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './dist/walk.mjs'.", "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/acorn-walk/dist/walk.mts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "Matched 'exports' condition 'default'.", "Using 'exports' subpath '.' with target './dist/walk.js'.", @@ -15,6 +17,8 @@ "File '/node_modules/acorn-walk/dist/walk.ts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.tsx' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'default'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/acorn-walk/dist/walk.d.ts', result '/node_modules/acorn-walk/dist/walk.d.ts'.", "======== Module name 'acorn-walk' was successfully resolved to '/node_modules/acorn-walk/dist/walk.d.ts' with Package ID 'acorn-walk/dist/walk.d.ts@8.2.0'. ========", "======== Resolving module 'acorn-walk' from '/index.ts'. ========", @@ -22,11 +26,13 @@ "File '/package.json' does not exist.", "Loading module 'acorn-walk' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "File '/node_modules/acorn-walk/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './dist/walk.mjs'.", "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/acorn-walk/dist/walk.mts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "Matched 'exports' condition 'default'.", "Using 'exports' subpath '.' with target './dist/walk.js'.", @@ -34,6 +40,8 @@ "File '/node_modules/acorn-walk/dist/walk.ts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.tsx' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'default'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/acorn-walk/dist/walk.d.ts', result '/node_modules/acorn-walk/dist/walk.d.ts'.", "======== Module name 'acorn-walk' was successfully resolved to '/node_modules/acorn-walk/dist/walk.d.ts' with Package ID 'acorn-walk/dist/walk.d.ts@8.2.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js index 02144e8380445..20deca3dbd2fb 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -54,11 +54,17 @@ File '/Users/name/projects/web/node_modules/yargs.ts' does not exist. File '/Users/name/projects/web/node_modules/yargs.tsx' does not exist. File '/Users/name/projects/web/node_modules/yargs.d.ts' does not exist. Found 'package.json' at '/Users/name/projects/web/node_modules/@types/yargs/package.json'. +Entering conditional exports. Matched 'exports' condition 'types'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'default'. Using 'exports' subpath '.' with target './index.d.ts'. File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exists - use it as a name resolution result. +Resolved under condition 'default'. +Exiting conditional exports. +Resolved under condition 'types'. +Exiting conditional exports. Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. ======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js index 5ef1629af560a..28a6ab7fd28d4 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js @@ -39,9 +39,12 @@ Found 'package.json' at '/user/username/projects/myproject/package.json'. Explicitly specified module resolution kind: 'NodeNext'. Resolving in ESM mode with conditions 'node', 'import', 'types'. File '/user/username/projects/myproject/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'default'. Using 'exports' subpath '.' with target './dist/index.js'. File '/user/username/projects/myproject/index.ts' exists - use it as a name resolution result. +Resolved under condition 'default'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/index.ts', result '/user/username/projects/myproject/index.ts'. ======== Module name '@this/package' was successfully resolved to '/user/username/projects/myproject/index.ts'. ======== File '/user/username/projects/myproject/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js index a1db17bcd32d3..7bc2102e1680d 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js @@ -66,12 +66,15 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg/package.json'. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Module name 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1'. ======== ======== Resolving module 'pkg1' from '/user/username/projects/myproject/index.ts'. ======== @@ -84,6 +87,7 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg1' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg1/package.json'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. @@ -91,18 +95,23 @@ File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a File '/user/username/projects/myproject/node_modules/pkg1/require.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. +Failed to resolve under condition 'require'. +Exiting conditional exports. Directory '/user/username/projects/myproject/node_modules/@types' does not exist, skipping all lookups in it. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. Directory '/user/node_modules' does not exist, skipping all lookups in it. Directory '/node_modules' does not exist, skipping all lookups in it. File '/user/username/projects/myproject/node_modules/pkg1/package.json' exists according to earlier cached lookups. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg1/require.js' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.jsx' does not exist. +Failed to resolve under condition 'require'. +Exiting conditional exports. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. Directory '/user/node_modules' does not exist, skipping all lookups in it. @@ -236,12 +245,15 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Module name 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1'. ======== File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js index fc84db6c07497..827b58d73b992 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js @@ -75,21 +75,27 @@ File '/package.json' does not exist according to earlier cached lookups. Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg/package.json'. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Type reference directive 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1', primary: false. ======== ======== Resolving type reference directive 'pkg1', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg1/package.json'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. +Failed to resolve under condition 'require'. +Exiting conditional exports. File '/user/username/projects/myproject/node_modules/@types/pkg1.d.ts' does not exist. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. @@ -251,10 +257,13 @@ File '/package.json' does not exist according to earlier cached lookups. Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Type reference directive 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1', primary: false. ======== File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. diff --git a/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts b/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts new file mode 100644 index 0000000000000..d9a1d480b8ef3 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts @@ -0,0 +1,33 @@ +// @moduleResolution: node16,nodenext,bundler +// @traceResolution: true +// @allowJs: true +// @noTypesAndSymbols: true +// @noEmit: true + +// This documents bug https://github.com/microsoft/TypeScript/issues/50762. + +// @Filename: /node_modules/dep/package.json +{ + "name": "dep", + "version": "1.0.0", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js", + "types": "./dist/index.d.ts", + } + } +} + +// @Filename: /node_modules/dep/dist/index.d.ts +export {}; + +// @Filename: /node_modules/dep/dist/index.mjs +export {}; + +// @Filename: /index.mts +import {} from "dep"; +// Should be an untyped resolution to dep/dist/index.mjs, +// but the first search is only for TS files, and when +// there's no dist/index.d.mts, it continues looking for +// matching conditions and resolves via `types`. \ No newline at end of file