Skip to content

Commit 3822e3e

Browse files
author
Andy
authored
tryGetModuleNameAsNodeModule: Ignore file extension (microsoft#24774)
1 parent 5138b47 commit 3822e3e

2 files changed

Lines changed: 2 additions & 9 deletions

File tree

src/compiler/moduleSpecifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ namespace ts.moduleSpecifiers {
248248
const mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main;
249249
if (mainFileRelative) {
250250
const mainExportFile = toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
251-
if (mainExportFile === getCanonicalFileName(path)) {
251+
if (removeFileExtension(mainExportFile) === removeFileExtension(getCanonicalFileName(path))) {
252252
return packageRootPath;
253253
}
254254
}

tests/cases/fourslash/importNameCodeFixNewImportNodeModules7.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@
1515
// @Filename: node_modules/package-name/package.json
1616
//// { "main": "bin/lib/libfile.js" }
1717

18-
19-
// In this case, importing the module by its package name:
20-
// import { f1 } from 'package-name'
21-
// could in theory work, however the resulting code compiles with a module resolution error
22-
// since bin/lib/libfile.d.ts isn't declared under "typings" in package.json
23-
// Therefore just import the module by its qualified path
24-
2518
verify.importFixAtPosition([
26-
`import { f1 } from "package-name/bin/lib/libfile";
19+
`import { f1 } from "package-name";
2720
2821
f1('');`
2922
]);

0 commit comments

Comments
 (0)