tryGetModuleNameAsNodeModule: Ignore file extension (#24774)

This commit is contained in:
Andy 2018-06-07 15:45:03 -07:00 committed by GitHub
parent 5138b4744d
commit 3822e3e4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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('');`
]);