Skip to content

Commit 64f205b

Browse files
committed
Add specialized error message
1 parent 34e9e08 commit 64f205b

File tree

32 files changed

+82
-78
lines changed

32 files changed

+82
-78
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,9 +4684,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
46844684
}
46854685
}
46864686

4687-
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
4687+
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean, errorMessage?: DiagnosticMessage): Symbol | undefined {
46884688
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
4689-
const errorMessage = isClassic ?
4689+
errorMessage ??= isClassic ?
46904690
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option
46914691
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
46924692
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage, ignoreErrors);
@@ -48516,7 +48516,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4851648516
}
4851748517
}
4851848518
else if (noUncheckedSideEffectImports && !importClause) {
48519-
void resolveExternalModuleName(node, node.moduleSpecifier);
48519+
void resolveExternalModuleName(node, node.moduleSpecifier, /*ignoreErrors*/ undefined, Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0);
4852048520
}
4852148521
}
4852248522
checkImportAttributes(node);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,6 +4007,10 @@
40074007
"category": "Error",
40084008
"code": 2881
40094009
},
4010+
"Cannot find module or type declarations for side-effect import of '{0}'.": {
4011+
"category": "Error",
4012+
"code": 2882
4013+
},
40104014

40114015
"Import declaration '{0}' is using private name '{1}'.": {
40124016
"category": "Error",

tests/baselines/reference/amdDependencyCommentName4.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
amdDependencyCommentName4.ts(6,8): error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
1+
amdDependencyCommentName4.ts(6,8): error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule1'.
22
amdDependencyCommentName4.ts(8,21): error TS2792: Cannot find module 'aliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
33
amdDependencyCommentName4.ts(11,26): error TS2792: Cannot find module 'aliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
44
amdDependencyCommentName4.ts(14,15): error TS2792: Cannot find module 'aliasedModule3'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
55
amdDependencyCommentName4.ts(17,21): error TS2792: Cannot find module 'aliasedModule4'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
6-
amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
6+
amdDependencyCommentName4.ts(20,8): error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule2'.
77

88

99
==== amdDependencyCommentName4.ts (6 errors) ====
@@ -14,7 +14,7 @@ amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedM
1414

1515
import "unaliasedModule1";
1616
~~~~~~~~~~~~~~~~~~
17-
!!! error TS2792: Cannot find module 'unaliasedModule1'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
17+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule1'.
1818

1919
import r1 = require("aliasedModule1");
2020
~~~~~~~~~~~~~~~~
@@ -38,4 +38,4 @@ amdDependencyCommentName4.ts(20,8): error TS2792: Cannot find module 'unaliasedM
3838

3939
import "unaliasedModule2";
4040
~~~~~~~~~~~~~~~~~~
41-
!!! error TS2792: Cannot find module 'unaliasedModule2'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
41+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'unaliasedModule2'.

tests/baselines/reference/autoAccessorDisallowedModifiers(target=es2017).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can
2323
autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2424
autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2525
autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
26-
autoAccessorDisallowedModifiers.ts(34,17): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
26+
autoAccessorDisallowedModifiers.ts(34,17): error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
2727
autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2828
autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
2929
autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
@@ -117,7 +117,7 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can
117117
~~~~~~~~
118118
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
119119
~~~
120-
!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
120+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
121121
accessor import {} from "x";
122122
~~~~~~~~
123123
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.

tests/baselines/reference/autoAccessorDisallowedModifiers(target=esnext).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can
2323
autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2424
autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2525
autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
26-
autoAccessorDisallowedModifiers.ts(34,17): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
26+
autoAccessorDisallowedModifiers.ts(34,17): error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
2727
autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
2828
autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
2929
autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
@@ -117,7 +117,7 @@ autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can
117117
~~~~~~~~
118118
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.
119119
~~~
120-
!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
120+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'x'.
121121
accessor import {} from "x";
122122
~~~~~~~~
123123
!!! error TS1275: 'accessor' modifier can only appear on a property declaration.

tests/baselines/reference/checkExportsObjectAssignPrototypeProperty.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
validator.ts(1,8): error TS2307: Cannot find module './' or its corresponding type declarations.
1+
validator.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of './'.
22
validator.ts(19,4): error TS2540: Cannot assign to 'readonlyProp' because it is a read-only property.
33
validator.ts(20,4): error TS2540: Cannot assign to 'readonlyAccessor' because it is a read-only property.
44
validator.ts(21,1): error TS2322: Type 'string' is not assignable to type 'number'.
@@ -9,7 +9,7 @@ validator.ts(23,1): error TS2322: Type 'number' is not assignable to type 'strin
99
==== validator.ts (6 errors) ====
1010
import "./";
1111
~~~~
12-
!!! error TS2307: Cannot find module './' or its corresponding type declarations.
12+
!!! error TS2882: Cannot find module or type declarations for side-effect import of './'.
1313

1414
import Person = require("./mod1");
1515

tests/baselines/reference/emit(jsx=preserve).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its correspondin
33
main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations.
44
main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations.
55
main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
6-
main.ts(7,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
6+
main.ts(7,8): error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
77
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
88
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
99
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
@@ -43,7 +43,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
4343
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
4444
import "./foo.ts";
4545
~~~~~~~~~~
46-
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
46+
!!! error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
4747
export * from "./foo.ts";
4848
~~~~~~~~~~
4949
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.

tests/baselines/reference/emit(jsx=react).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.ts(3,16): error TS2307: Cannot find module '../foo.mts' or its correspondin
33
main.ts(4,16): error TS2307: Cannot find module '../../foo.cts' or its corresponding type declarations.
44
main.ts(5,16): error TS2307: Cannot find module './foo.tsx' or its corresponding type declarations.
55
main.ts(6,22): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
6-
main.ts(7,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
6+
main.ts(7,8): error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
77
main.ts(8,15): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
88
main.ts(10,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
99
main.ts(11,8): error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
@@ -43,7 +43,7 @@ no.ts(11,8): error TS2307: Cannot find module 'node:path' or its corresponding t
4343
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
4444
import "./foo.ts";
4545
~~~~~~~~~~
46-
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
46+
!!! error TS2882: Cannot find module or type declarations for side-effect import of './foo.ts'.
4747
export * from "./foo.ts";
4848
~~~~~~~~~~
4949
!!! error TS2307: Cannot find module './foo.ts' or its corresponding type declarations.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations.
1+
es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.
22

33

44
==== es6ImportWithoutFromClauseInEs5_0.ts (0 errors) ====
@@ -7,4 +7,4 @@ es6ImportWithoutFromClauseInEs5_1.ts(1,8): error TS2307: Cannot find module 'es6
77
==== es6ImportWithoutFromClauseInEs5_1.ts (1 errors) ====
88
import "es6ImportWithoutFromClauseInEs5_0";
99
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10-
!!! error TS2307: Cannot find module 'es6ImportWithoutFromClauseInEs5_0' or its corresponding type declarations.
10+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'es6ImportWithoutFromClauseInEs5_0'.

tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
client.ts(1,1): error TS1191: An import declaration cannot have modifiers.
2-
client.ts(1,15): error TS2307: Cannot find module 'server' or its corresponding type declarations.
2+
client.ts(1,15): error TS2882: Cannot find module or type declarations for side-effect import of 'server'.
33

44

55
==== server.ts (0 errors) ====
@@ -10,4 +10,4 @@ client.ts(1,15): error TS2307: Cannot find module 'server' or its corresponding
1010
~~~~~~
1111
!!! error TS1191: An import declaration cannot have modifiers.
1212
~~~~~~~~
13-
!!! error TS2307: Cannot find module 'server' or its corresponding type declarations.
13+
!!! error TS2882: Cannot find module or type declarations for side-effect import of 'server'.

0 commit comments

Comments
 (0)