Skip to content

Commit 9ea4d93

Browse files
authored
Merge pull request #23957 from paulkoerbitz/16675-better-error-message-for-dynamic-import
Fix #16675: Better error message for dynamic import with ES2015 modules
2 parents e27fb06 + 89d2bae commit 9ea4d93

5 files changed

+16
-16
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28131,7 +28131,7 @@ namespace ts {
2813128131

2813228132
function checkGrammarImportCallExpression(node: ImportCall): boolean {
2813328133
if (moduleKind === ModuleKind.ES2015) {
28134-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules);
28134+
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_is_only_supported_when_module_flag_is_commonjs_or_esNext);
2813528135
}
2813628136

2813728137
if (node.typeArguments) {

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@
895895
"category": "Error",
896896
"code": 1322
897897
},
898-
"Dynamic import cannot be used when targeting ECMAScript 2015 modules.": {
898+
"Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.": {
899899
"category": "Error",
900900
"code": 1323
901901
},
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
2-
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
3-
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
1+
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
2+
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
3+
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
44

55

66
==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
@@ -9,16 +9,16 @@ tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic import c
99
==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ====
1010
import("./0");
1111
~~~~~~~~~~~~~
12-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
12+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1313
var p1 = import("./0");
1414
~~~~~~~~~~~~~
15-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
15+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1616
p1.then(zero => {
1717
return zero.foo();
1818
})
1919

2020
function foo() {
2121
const p2 = import("./0");
2222
~~~~~~~~~~~~~
23-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
23+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
2424
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
2-
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
1+
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
2+
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
33

44

55
==== tests/cases/conformance/dynamicImport/foo.ts (0 errors) ====
@@ -9,7 +9,7 @@ tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic impo
99
async function foo() {
1010
return await import((await import("./foo")).default);
1111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
12+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1313
~~~~~~~~~~~~~~~
14-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
14+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1515
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
2-
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
1+
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
2+
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
33

44

55
==== tests/cases/conformance/dynamicImport/foo.ts (0 errors) ====
@@ -9,7 +9,7 @@ tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic impo
99
async function foo() {
1010
return await import((await import("./foo")).default);
1111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
12+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1313
~~~~~~~~~~~~~~~
14-
!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.
14+
!!! error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
1515
}

0 commit comments

Comments
 (0)