Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 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 = resolveExternalModuleName(node, node.moduleSpecifier!)!;
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,9 +3105,12 @@ 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);
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
const errorMessage = isClassic?
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage);
}

function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation = false): Symbol | undefined {
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
4 changes: 2 additions & 2 deletions tests/baselines/reference/aliasesInSystemModule1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/aliasesInSystemModule1.ts(1,24): error TS2307: Cannot find module 'foo' or its corresponding type declarations.
tests/cases/compiler/aliasesInSystemModule1.ts(1,24): 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/aliasesInSystemModule1.ts (1 errors) ====
import alias = require('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
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/ambientExternalModuleInAnotherExternalModule.ts(4,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): error TS2307: Cannot find module 'ext' or its corresponding type declarations.
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): error TS2792: Cannot find module 'ext'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts (2 errors) ====
Expand All @@ -15,5 +15,5 @@ tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): erro
// Cannot resolve this ext module reference
import ext = require("ext");
~~~~~
!!! error TS2307: Cannot find module 'ext' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'ext'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
var x = ext;
4 changes: 2 additions & 2 deletions tests/baselines/reference/amdDependencyComment2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/amdDependencyComment2.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.
tests/cases/compiler/amdDependencyComment2.ts(3,21): error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/amdDependencyComment2.ts (1 errors) ====
///<amd-dependency path='bar'/>

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
m1.f();
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/amdDependencyCommentName2.ts (1 errors) ====
///<amd-dependency path='bar' name='b'/>

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
m1.f();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/amdDependencyCommentName3.ts (1 errors) ====
Expand All @@ -8,5 +8,5 @@ tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot fi

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'm2'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
m1.f();
16 changes: 8 additions & 8 deletions tests/baselines/reference/amdDependencyCommentName4.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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(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.
tests/cases/compiler/amdDependencyCommentName4.ts(8,21): error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
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 TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/amdDependencyCommentName4.ts (4 errors) ====
Expand All @@ -14,22 +14,22 @@ tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot f

import r1 = require("aliasedModule1");
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule1' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
r1;

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";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule3' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
d;

import * as ns from "aliasedModule4";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule4' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
ns;

import "unaliasedModule2";
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/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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/badExternalModuleReference.ts(1,21): error TS2307: Cannot find module 'garbage' or its corresponding type declarations.
tests/cases/compiler/badExternalModuleReference.ts(1,21): error TS2792: Cannot find module 'garbage'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?


==== tests/cases/compiler/badExternalModuleReference.ts (1 errors) ====
import a1 = require("garbage");
~~~~~~~~~
!!! error TS2307: Cannot find module 'garbage' or its corresponding type declarations.
!!! error TS2792: Cannot find module 'garbage'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
export declare var a: {
test1: a1.connectModule;
(): a1.connectExport;
Expand Down
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?

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/commentOnImportStatement1.ts(3,22): error TS2307: Cannot find module './foo' or its corresponding type declarations.
tests/cases/compiler/commentOnImportStatement1.ts(3,22): 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/commentOnImportStatement1.ts (1 errors) ====
/* Copyright */

import foo = require('./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?

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


==== tests/cases/compiler/copyrightWithNewLine1.ts (1 errors) ====
Expand All @@ -8,7 +8,7 @@ tests/cases/compiler/copyrightWithNewLine1.ts(5,24): error TS2307: Cannot find m

import model = require("./greeter")
~~~~~~~~~~~
!!! error TS2307: Cannot find module './greeter' or its corresponding type declarations.
!!! error TS2792: Cannot find module './greeter'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
var el = document.getElementById('content');
var greeter = new model.Greeter(el);
/** things */
Expand Down
Loading