Skip to content

Commit

Permalink
tryGetModuleNameAsNodeModule: Ignore file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Jun 7, 2018
1 parent e947154 commit 67e3473
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace ts.moduleSpecifiers {
const mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main;
if (mainFileRelative) {
const mainExportFile = toPath(mainFileRelative, packageRootPath, getCanonicalFileName);
if (mainExportFile === getCanonicalFileName(path)) {
if (removeFileExtension(mainExportFile) === removeFileExtension(getCanonicalFileName(path))) {
return packageRootPath;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
// @Filename: node_modules/package-name/package.json
//// { "main": "bin/lib/libfile.js" }


// In this case, importing the module by its package name:
// import { f1 } from 'package-name'
// could in theory work, however the resulting code compiles with a module resolution error
// since bin/lib/libfile.d.ts isn't declared under "typings" in package.json
// Therefore just import the module by its qualified path

verify.importFixAtPosition([
`import { f1 } from "package-name/bin/lib/libfile";
`import { f1 } from "package-name";
f1('');`
]);

0 comments on commit 67e3473

Please sign in to comment.