diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b73558cfc6b..ed9f010c56a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1077,6 +1077,8 @@ namespace ts { const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); if (importedFile && resolution.isExternalLibraryImport) { + // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, + // this check is ok. Otherwise this would be never true for javascript file if (!isExternalModule(importedFile)) { const start = getTokenPosOfNode(file.imports[i], file); fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); diff --git a/tests/baselines/reference/jsFileCompilationExternalPackageError.errors.txt b/tests/baselines/reference/jsFileCompilationExternalPackageError.errors.txt new file mode 100644 index 00000000000..58111c777f1 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationExternalPackageError.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/moduleA/a.js(2,17): error TS2656: Exported external package typings file 'tests/cases/compiler/node_modules/b.ts' is not a module. Please contact the package author to update the package definition. + + +==== tests/cases/compiler/moduleA/a.js (1 errors) ==== + + import {a} from "b"; + ~~~ +!!! error TS2656: Exported external package typings file 'b.ts' is not a module. Please contact the package author to update the package definition. + a++; + import {c} from "c"; + c++; + +==== tests/cases/compiler/node_modules/b.ts (0 errors) ==== + var a = 10; + +==== tests/cases/compiler/node_modules/c.js (0 errors) ==== + exports.a = 10; + c = 10; + \ No newline at end of file diff --git a/tests/cases/compiler/jsFileCompilationExternalPackageError.ts b/tests/cases/compiler/jsFileCompilationExternalPackageError.ts new file mode 100644 index 00000000000..cb9d32adb82 --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationExternalPackageError.ts @@ -0,0 +1,16 @@ +// @allowJs: true +// @noEmit: true +// @module: commonjs + +// @filename: moduleA/a.js +import {a} from "b"; +a++; +import {c} from "c"; +c++; + +// @filename: node_modules/b.ts +var a = 10; + +// @filename: node_modules/c.js +exports.a = 10; +c = 10;