diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts
index bc606ffebe354..b1e3ffbdac6a3 100644
--- a/src/compiler/moduleNameResolver.ts
+++ b/src/compiler/moduleNameResolver.ts
@@ -340,7 +340,11 @@ namespace ts {
}
const failedLookupLocations: string[] = [];
- const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.AllFeatures, conditions: ["node", "require", "types"] };
+ const features =
+ getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
+ getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
+ NodeResolutionFeatures.None;
+ const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features, conditions: ["node", "require", "types"] };
let resolved = primaryLookup();
let primary = true;
if (!resolved) {
@@ -1186,6 +1190,10 @@ namespace ts {
ExportsPatternTrailers = 1 << 4,
AllFeatures = Imports | SelfName | Exports | ExportsPatternTrailers,
+ Node12Default = Imports | SelfName | Exports,
+
+ NodeNextDefault = AllFeatures,
+
EsmMode = 1 << 5,
}
@@ -1193,7 +1201,7 @@ namespace ts {
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
return nodeNextModuleNameResolverWorker(
- NodeResolutionFeatures.Imports | NodeResolutionFeatures.SelfName | NodeResolutionFeatures.Exports,
+ NodeResolutionFeatures.Node12Default,
moduleName,
containingFile,
compilerOptions,
@@ -1208,7 +1216,7 @@ namespace ts {
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
return nodeNextModuleNameResolverWorker(
- NodeResolutionFeatures.AllFeatures,
+ NodeResolutionFeatures.NodeNextDefault,
moduleName,
containingFile,
compilerOptions,
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).js b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).js
new file mode 100644
index 0000000000000..9843fbbf1ee00
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).js
@@ -0,0 +1,18 @@
+//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////
+
+//// [index.d.ts]
+interface GlobalThing { a: number }
+//// [package.json]
+{
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+}
+//// [usage.ts]
+///
+
+const a: GlobalThing = { a: 0 };
+
+//// [usage.js]
+///
+var a = { a: 0 };
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).symbols b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).symbols
new file mode 100644
index 0000000000000..b97c41025fe42
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).symbols
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : Symbol(a, Decl(usage.ts, 2, 5))
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(a, Decl(usage.ts, 2, 24))
+
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).types b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).types
new file mode 100644
index 0000000000000..b107f91dcb264
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=commonjs).types
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>a : number
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : GlobalThing
+>{ a: 0 } : { a: number; }
+>a : number
+>0 : 0
+
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).errors.txt b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).errors.txt
new file mode 100644
index 0000000000000..179a40218dc53
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).errors.txt
@@ -0,0 +1,17 @@
+tests/cases/compiler/usage.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'.
+
+
+==== tests/cases/compiler/node_modules/pkg/index.d.ts (0 errors) ====
+ interface GlobalThing { a: number }
+==== tests/cases/compiler/node_modules/pkg/package.json (0 errors) ====
+ {
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+ }
+==== tests/cases/compiler/usage.ts (1 errors) ====
+ ///
+ ~~~
+!!! error TS2688: Cannot find type definition file for 'pkg'.
+
+ const a: GlobalThing = { a: 0 };
\ No newline at end of file
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).js b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).js
new file mode 100644
index 0000000000000..89dd2c7541a29
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).js
@@ -0,0 +1,18 @@
+//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////
+
+//// [index.d.ts]
+interface GlobalThing { a: number }
+//// [package.json]
+{
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+}
+//// [usage.ts]
+///
+
+const a: GlobalThing = { a: 0 };
+
+//// [usage.js]
+///
+const a = { a: 0 };
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).symbols b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).symbols
new file mode 100644
index 0000000000000..b97c41025fe42
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).symbols
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : Symbol(a, Decl(usage.ts, 2, 5))
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(a, Decl(usage.ts, 2, 24))
+
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).types b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).types
new file mode 100644
index 0000000000000..b107f91dcb264
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=node12).types
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>a : number
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : GlobalThing
+>{ a: 0 } : { a: number; }
+>a : number
+>0 : 0
+
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).errors.txt b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).errors.txt
new file mode 100644
index 0000000000000..179a40218dc53
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).errors.txt
@@ -0,0 +1,17 @@
+tests/cases/compiler/usage.ts(1,23): error TS2688: Cannot find type definition file for 'pkg'.
+
+
+==== tests/cases/compiler/node_modules/pkg/index.d.ts (0 errors) ====
+ interface GlobalThing { a: number }
+==== tests/cases/compiler/node_modules/pkg/package.json (0 errors) ====
+ {
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+ }
+==== tests/cases/compiler/usage.ts (1 errors) ====
+ ///
+ ~~~
+!!! error TS2688: Cannot find type definition file for 'pkg'.
+
+ const a: GlobalThing = { a: 0 };
\ No newline at end of file
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js
new file mode 100644
index 0000000000000..89dd2c7541a29
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).js
@@ -0,0 +1,18 @@
+//// [tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts] ////
+
+//// [index.d.ts]
+interface GlobalThing { a: number }
+//// [package.json]
+{
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+}
+//// [usage.ts]
+///
+
+const a: GlobalThing = { a: 0 };
+
+//// [usage.js]
+///
+const a = { a: 0 };
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).symbols b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).symbols
new file mode 100644
index 0000000000000..b97c41025fe42
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).symbols
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(GlobalThing.a, Decl(index.d.ts, 0, 23))
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : Symbol(a, Decl(usage.ts, 2, 5))
+>GlobalThing : Symbol(GlobalThing, Decl(index.d.ts, 0, 0))
+>a : Symbol(a, Decl(usage.ts, 2, 24))
+
diff --git a/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).types b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).types
new file mode 100644
index 0000000000000..b107f91dcb264
--- /dev/null
+++ b/tests/baselines/reference/tripleSlashTypesReferenceWithMissingExports(module=nodenext).types
@@ -0,0 +1,13 @@
+=== tests/cases/compiler/node_modules/pkg/index.d.ts ===
+interface GlobalThing { a: number }
+>a : number
+
+=== tests/cases/compiler/usage.ts ===
+///
+
+const a: GlobalThing = { a: 0 };
+>a : GlobalThing
+>{ a: 0 } : { a: number; }
+>a : number
+>0 : 0
+
diff --git a/tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts b/tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts
new file mode 100644
index 0000000000000..d5b58f5077fa2
--- /dev/null
+++ b/tests/cases/compiler/tripleSlashTypesReferenceWithMissingExports.ts
@@ -0,0 +1,13 @@
+// @module: commonjs,node12,nodenext
+// @filename: node_modules/pkg/index.d.ts
+interface GlobalThing { a: number }
+// @filename: node_modules/pkg/package.json
+{
+ "name": "pkg",
+ "types": "index.d.ts",
+ "exports": "some-other-thing.js"
+}
+// @filename: usage.ts
+///
+
+const a: GlobalThing = { a: 0 };
\ No newline at end of file