Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,7 @@ namespace ts {
}

function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias = false): Symbol | undefined {
const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier!)!; // TODO: GH#18217
const moduleSymbol = resolveExternalModuleNameWorker(node, node.moduleSpecifier!, false ? undefined : Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option)!;
const name = specifier.propertyName || specifier.name;
const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(compilerOptions.allowSyntheticDefaultImports || compilerOptions.esModuleInterop);
const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier!, dontResolveAlias, suppressInteropError);
Expand Down Expand Up @@ -3105,7 +3105,6 @@ namespace ts {
}
}


function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations);
}
Expand Down Expand Up @@ -35289,7 +35288,7 @@ namespace ts {
}
}
else {
const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier);
const moduleExisted = resolveExternalModuleNameWorker(node, node.moduleSpecifier, false ? undefined : Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option);
if (moduleExisted) {
forEach(importClause.namedBindings.elements, checkImportBinding);
}
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,11 @@
"category": "Error",
"code": 2791
},
"Cannot find module '{0}'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?": {
"category": "Error",
"code": 2792
},


"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tscWatch/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace ts.tscWatch {

export function getDiagnosticModuleNotFoundOfFile(program: Program, file: File, moduleName: string) {
const quotedModuleName = `"${moduleName}"`;
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, moduleName);
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option, moduleName);
}

export function runQueuedTimeoutCallbacks(sys: WatchedSystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ namespace ts.projectSystem {
let diags = project.getLanguageService().getSemanticDiagnostics(root.path);
assert.equal(diags.length, 1);
const diag = diags[0];
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations.code);
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar' or its corresponding type declarations.");
assert.equal(diag.code, Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option.code);
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?");
callsTrackingHost.verifyCalledOn(CalledMapsWithSingleArg.fileExists, imported.path);


Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/symLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ new C();`
verifyWatchedFilesAndDirectories(session.testhost, filesInProjectWithUnresolvedModule, watchedDirectoriesWithUnresolvedModule, nonRecursiveWatchedDirectories);
const startOffset = recognizersDateTimeSrcFile.content.indexOf('"') + 1;
verifyErrors(session, [
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, [moduleName])
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option, [moduleName])
]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/aliasesInSystemModule2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/aliasesInSystemModule2.ts(1,21): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
tests/cases/compiler/aliasesInSystemModule2.ts(1,21): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/aliasesInSystemModule2.ts (1 errors) ====
import {alias} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import cls = alias.Class;
export import cls2 = alias.Class;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/compiler/amdDependencyCommentName4.ts(8,21): error TS2307: Cannot find module 'aliasedModule1' or its corresponding type declarations.
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2' or its corresponding type declarations.
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3' or its corresponding type declarations.
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4' or its corresponding type declarations.

Expand All @@ -19,7 +19,7 @@ tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot f

import {p1, p2, p3} from "aliasedModule2";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
p1;

import d from "aliasedModule3";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts(1,27): error TS2307: Cannot find module 'missing' or its corresponding type declarations.
tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts(1,27): error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/conformance/async/es2017/asyncAwaitIsolatedModules_es2017.ts (1 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

declare var p: Promise<number>;
declare var mp: MyPromise<number>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts(1,27): error TS2307: Cannot find module 'missing' or its corresponding type declarations.
tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts(1,27): error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/conformance/async/es5/asyncAwaitIsolatedModules_es5.ts (1 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

declare var p: Promise<number>;
declare var mp: MyPromise<number>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2307: Cannot find module 'missing' or its corresponding type declarations.
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts (1 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'missing'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

declare var p: Promise<number>;
declare var mp: MyPromise<number>;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/cachedModuleResolution6.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/d/e/app.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
/a/b/c/lib.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
8 changes: 4 additions & 4 deletions tests/baselines/reference/cachedModuleResolution7.errors.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/d/e/app.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
/a/b/c/lib.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

8 changes: 4 additions & 4 deletions tests/baselines/reference/cachedModuleResolution8.errors.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/d/e/app.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
/a/b/c/lib.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
8 changes: 4 additions & 4 deletions tests/baselines/reference/cachedModuleResolution9.errors.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
/a/b/c/d/e/app.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
/a/b/c/lib.ts(1,17): error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== /a/b/c/lib.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== /a/b/c/d/e/app.ts (1 errors) ====
import {x} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'foo'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

24 changes: 12 additions & 12 deletions tests/baselines/reference/deduplicateImportsInSystem.errors.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2307: Cannot find module 'f1' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2307: Cannot find module 'f2' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2307: Cannot find module 'f3' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2307: Cannot find module 'f2' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2307: Cannot find module 'f2' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2307: Cannot find module 'f1' or its corresponding type declarations.
tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2792: Cannot find module 'f1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2792: Cannot find module 'f3'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2792: Cannot find module 'f1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/deduplicateImportsInSystem.ts (6 errors) ====
import {A} from "f1";
~~~~
!!! error TS2307: Cannot find module 'f1' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import {B} from "f2";
~~~~
!!! error TS2307: Cannot find module 'f2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import {C} from "f3";
~~~~
!!! error TS2307: Cannot find module 'f3' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f3'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import {D} from 'f2';
~~~~
!!! error TS2307: Cannot find module 'f2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import {E} from "f2";
~~~~
!!! error TS2307: Cannot find module 'f2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
import {F} from 'f1';
~~~~
!!! error TS2307: Cannot find module 'f1' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'f1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

console.log(A + B + C + D + E + F)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests/cases/compiler/errorForBareSpecifierWithImplicitModuleResolutionNone.ts(3,23): error TS2792: Cannot find module 'non-existent-module'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/errorForBareSpecifierWithImplicitModuleResolutionNone.ts (1 errors) ====
// This would be classed as moduleResolutionKind: Classic

import { thing } from "non-existent-module";
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2792: Cannot find module 'non-existent-module'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
thing()

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [errorForBareSpecifierWithImplicitModuleResolutionNone.ts]
// This would be classed as moduleResolutionKind: Classic

import { thing } from "non-existent-module";
thing()


//// [errorForBareSpecifierWithImplicitModuleResolutionNone.js]
// This would be classed as moduleResolutionKind: Classic
import { thing } from "non-existent-module";
thing();
Loading