Skip to content

improve error message TS2307 #27054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2969,7 +2969,7 @@ namespace ts {


function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : Diagnostics.Cannot_find_module_0);
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations);
}

function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage | undefined, isForAugmentation = false): Symbol | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@
"category": "Error",
"code": 2306
},
"Cannot find module '{0}'.": {
"Cannot find module '{0}' or its corresponding type declarations.": {
"category": "Error",
"code": 2307
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/fixCannotFindModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ts.codefix {
const fixName = "fixCannotFindModule";
const fixIdInstallTypesPackage = "installTypesPackage";

const errorCodeCannotFindModule = Diagnostics.Cannot_find_module_0.code;
const errorCodeCannotFindModule = Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations.code;
const errorCodes = [
errorCodeCannotFindModule,
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type.code,
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, moduleName);
return getDiagnosticOfFileFromProgram(program, file.path, file.content.indexOf(quotedModuleName), quotedModuleName.length, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, moduleName);
}

export type TscWatchCompileChange = (
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.code);
assert.equal(flattenDiagnosticMessageText(diag.messageText, "\n"), "Cannot find module 'bar'.");
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.");
callsTrackingHost.verifyCalledOn(CalledMapsWithSingleArg.fileExists, imported.path);


Expand Down Expand Up @@ -474,8 +474,8 @@ namespace ts.projectSystem {

const project = service.configuredProjects.get(tsconfig.path)!;
checkProjectActualFiles(project, files.map(f => f.path));
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file1.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(file2.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);

const debugTypesFile: File = {
path: `${projectLocation}/node_modules/debug/index.d.ts`,
Expand Down Expand Up @@ -682,7 +682,7 @@ namespace ts.projectSystem {

const project = service.configuredProjects.get(tsconfig.path)!;
checkProjectActualFiles(project, files.map(f => f.path));
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug'."]);
assert.deepEqual(project.getLanguageService().getSemanticDiagnostics(app.path).map(diag => diag.messageText), ["Cannot find module 'debug' or its corresponding type declarations."]);

const debugTypesFile: File = {
path: `${projectLocation}/node_modules/@types/debug/index.d.ts`,
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/projectErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ console.log(blabla);`
createDiagnostic(
span.start,
span.end,
Diagnostics.Cannot_find_module_0,
Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations,
["@angular/core"]
)
];
Expand Down
8 changes: 4 additions & 4 deletions src/testRunner/unittests/tsserver/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace ts.projectSystem {
);
let diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
verifyDiagnostics(diags, [
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
]);

host.reloadFS([file1, moduleFile]);
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace ts.projectSystem {
file: file1,
syntax: [],
semantic: [
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0, ["pad"])
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + '"pad"'.length }, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, ["pad"])
],
suggestion: []
}]
Expand Down Expand Up @@ -342,7 +342,7 @@ namespace ts.projectSystem {
host.runQueuedTimeoutCallbacks();
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
verifyDiagnostics(diags, [
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
]);
assert.equal(diags.length, 1);

Expand Down Expand Up @@ -393,7 +393,7 @@ namespace ts.projectSystem {
host.runQueuedTimeoutCallbacks();
diags = session.executeCommand(getErrRequest).response as server.protocol.Diagnostic[];
verifyDiagnostics(diags, [
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
{ diagnosticMessage: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, errorTextArguments: ["./moduleFile"] }
]);

moduleFile.path = moduleFileOldPath;
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 @@ -212,7 +212,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, [moduleName])
createDiagnostic({ line: 1, offset: startOffset }, { line: 1, offset: startOffset + moduleNameInFile.length }, Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations, [moduleName])
]);
}

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'.
tests/cases/compiler/aliasesInSystemModule1.ts(1,24): error TS2307: Cannot find module 'foo' or its corresponding type declarations.


==== tests/cases/compiler/aliasesInSystemModule1.ts (1 errors) ====
import alias = require('foo');
~~~~~
!!! error TS2307: Cannot find module 'foo'.
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
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'.
tests/cases/compiler/aliasesInSystemModule2.ts(1,21): error TS2307: Cannot find module 'foo' or its corresponding type declarations.


==== tests/cases/compiler/aliasesInSystemModule2.ts (1 errors) ====
import {alias} from "foo";
~~~~~
!!! error TS2307: Cannot find module 'foo'.
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations.
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'.
tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(9,22): error TS2307: Cannot find module 'ext' or its corresponding type declarations.


==== 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'.
!!! error TS2307: Cannot find module 'ext' or its corresponding type declarations.
var x = ext;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,25): error TS2307: Cannot find module './SubModule'.
tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,25): error TS2307: Cannot find module './SubModule' or its corresponding type declarations.


==== tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts (2 errors) ====
Expand All @@ -8,7 +8,7 @@ tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
~~~~~~~~~~~~~
!!! error TS2307: Cannot find module './SubModule'.
!!! error TS2307: Cannot find module './SubModule' or its corresponding type declarations.
class SubModule {
public static StaticVar: number;
public InstanceVar: number;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/amdDependencyComment1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/amdDependencyComment1.ts(3,21): error TS2307: Cannot find module 'm2'.
tests/cases/compiler/amdDependencyComment1.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.


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

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2'.
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
m1.f();
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'.
tests/cases/compiler/amdDependencyComment2.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.


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

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2'.
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
m1.f();
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find module 'm2'.
tests/cases/compiler/amdDependencyCommentName1.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.


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

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2'.
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
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'.
tests/cases/compiler/amdDependencyCommentName2.ts(3,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.


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

import m1 = require("m2")
~~~~
!!! error TS2307: Cannot find module 'm2'.
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
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'.
tests/cases/compiler/amdDependencyCommentName3.ts(5,21): error TS2307: Cannot find module 'm2' or its corresponding type declarations.


==== 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'.
!!! error TS2307: Cannot find module 'm2' or its corresponding type declarations.
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'.
tests/cases/compiler/amdDependencyCommentName4.ts(11,26): error TS2307: Cannot find module 'aliasedModule2'.
tests/cases/compiler/amdDependencyCommentName4.ts(14,15): error TS2307: Cannot find module 'aliasedModule3'.
tests/cases/compiler/amdDependencyCommentName4.ts(17,21): error TS2307: Cannot find module 'aliasedModule4'.
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 (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'.
!!! error TS2307: Cannot find module 'aliasedModule1' or its corresponding type declarations.
r1;

import {p1, p2, p3} from "aliasedModule2";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule2'.
!!! error TS2307: Cannot find module 'aliasedModule2' or its corresponding type declarations.
p1;

import d from "aliasedModule3";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule3'.
!!! error TS2307: Cannot find module 'aliasedModule3' or its corresponding type declarations.
d;

import * as ns from "aliasedModule4";
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'aliasedModule4'.
!!! error TS2307: Cannot find module 'aliasedModule4' or its corresponding type declarations.
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'.
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 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing'.
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.

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'.
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 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing'.
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.

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'.
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 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing'.
!!! error TS2307: Cannot find module 'missing' or its corresponding type declarations.

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'.
tests/cases/compiler/badExternalModuleReference.ts(1,21): error TS2307: Cannot find module 'garbage' or its corresponding type declarations.


==== tests/cases/compiler/badExternalModuleReference.ts (1 errors) ====
import a1 = require("garbage");
~~~~~~~~~
!!! error TS2307: Cannot find module 'garbage'.
!!! error TS2307: Cannot find module 'garbage' or its corresponding type declarations.
export declare var a: {
test1: a1.connectModule;
(): a1.connectExport;
Expand Down
Loading