Skip to content

Commit 1f95af0

Browse files
committed
Do not resolve require calls in typescript files even if it contains dynamic import
Fixes #38611
1 parent 913ee19 commit 1f95af0

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ namespace ts {
21762176
const r = /import|require/g;
21772177
while (r.exec(file.text) !== null) { // eslint-disable-line no-null/no-null
21782178
const node = getNodeAtPosition(file, r.lastIndex);
2179-
if (isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true)) {
2179+
if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true)) {
21802180
imports = append(imports, node.arguments[0]);
21812181
}
21822182
// we have to check the argument list has length of 1. We will still have to process these even though we have parsing error.

tests/baselines/reference/moduleResolutionWithRequireAndImport.trace.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,5 @@
33
"Module resolution kind is not specified, using 'NodeJs'.",
44
"Loading module as file / folder, candidate module location '/other', target file type 'TypeScript'.",
55
"File '/other.ts' exist - use it as a name resolution result.",
6-
"======== Module name './other' was successfully resolved to '/other.ts'. ========",
7-
"======== Resolving module '../outside-of-rootdir/foo' from '/index.ts'. ========",
8-
"Module resolution kind is not specified, using 'NodeJs'.",
9-
"Loading module as file / folder, candidate module location '/outside-of-rootdir/foo', target file type 'TypeScript'.",
10-
"Directory '/outside-of-rootdir' does not exist, skipping all lookups in it.",
11-
"Loading module as file / folder, candidate module location '/outside-of-rootdir/foo', target file type 'JavaScript'.",
12-
"Directory '/outside-of-rootdir' does not exist, skipping all lookups in it.",
13-
"======== Module name '../outside-of-rootdir/foo' was not resolved. ========"
6+
"======== Module name './other' was successfully resolved to '/other.ts'. ========"
147
]

0 commit comments

Comments
 (0)