Skip to content

Commit

Permalink
tryGetModuleNameAsNodeModule: Ignore file extension (#24774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Jun 7, 2018
1 parent 5138b47 commit 3822e3e
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 3822e3e

Please sign in to comment.