From 1e24dcb2cba7b50529c64fc3492c9449ac3cdaf5 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 9 Jan 2023 12:03:19 -0800 Subject: [PATCH 1/5] Add additional diagnostic for packages that only resolve under non-exports-respecting modes --- src/compiler/checker.ts | 24 +++++++++++++- src/compiler/diagnosticMessages.json | 8 +++++ src/compiler/moduleNameResolver.ts | 33 +++++++++++++++---- src/compiler/types.ts | 2 ++ ...cksTypesVersions(module=node16).errors.txt | 4 +++ ...cksTypesVersions(module=node16).trace.json | 19 +++++++++++ ...sTypesVersions(module=nodenext).errors.txt | 4 +++ ...sTypesVersions(module=nodenext).trace.json | 19 +++++++++++ ...rationConditions(module=node16).errors.txt | 2 ++ ...tionConditions(module=nodenext).errors.txt | 2 ++ 10 files changed, 110 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 47288fdde3259..e64a81a19b54a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -311,6 +311,7 @@ import { getOwnKeys, getParameterSymbolFromJSDoc, getParseTreeNode, + getPathComponents, getPropertyAssignmentAliasLikeExpression, getPropertyNameForPropertyNameNode, getResolutionDiagnostic, @@ -814,6 +815,7 @@ import { nodeIsPresent, nodeIsSynthesized, NodeLinks, + nodeModulesPathPart, nodeStartsNewLexicalEnvironment, NodeWithTypeArguments, NonNullChain, @@ -4899,7 +4901,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } else { - error(errorNode, moduleNotFoundError, moduleReference); + const legacyResult = currentSourceFile.resolvedModules?.get(moduleReference, mode)?.legacyResult; + if (legacyResult) { + const isInTypesScope = legacyResult.indexOf(nodeModulesPathPart + "@types/") > -1; + const moduleNameParts = getPathComponents(moduleReference); + moduleNameParts.shift(); // Empty string for nonrelative module name + if (moduleNameParts.length > 1 && moduleNameParts[0] === "@types") { + moduleNameParts.shift(); + } + const isScopedLibrary = moduleNameParts.length > 1 && startsWith(moduleNameParts[0], "@"); + const libraryName = isScopedLibrary ? `${moduleNameParts[0]}/${moduleNameParts[1]}` : moduleNameParts[0]; + const details = chainDiagnosticMessages( + /*details*/ undefined, + Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json, + legacyResult, + isInTypesScope ? `@types/${mangleScopedPackageName(libraryName)}` : libraryName + ); + diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, chainDiagnosticMessages(details, moduleNotFoundError, moduleReference))); + } + else { + error(errorNode, moduleNotFoundError, moduleReference); + } } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7573cbc29eaf3..85adb10def96b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5219,6 +5219,14 @@ "category": "Message", "code": 6276 }, + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.": { + "category": "Message", + "code": 6277 + }, + "There are types at '{0}', but this result could not be resolved when respecting package.json \"exports\". The '{1}' library may need to update its package.json.": { + "category": "Message", + "code": 6278 + }, "Enable project compilation": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index be8573b075db3..909863d3653f7 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -214,7 +214,8 @@ function createResolvedModuleWithFailedLookupLocations( failedLookupLocations: string[], affectingLocations: string[], diagnostics: Diagnostic[], - resultFromCache: ResolvedModuleWithFailedLookupLocations | undefined + resultFromCache: ResolvedModuleWithFailedLookupLocations | undefined, + legacyResult?: string, ): ResolvedModuleWithFailedLookupLocations { if (resultFromCache) { resultFromCache.failedLookupLocations = updateResolutionField(resultFromCache.failedLookupLocations, failedLookupLocations); @@ -234,6 +235,7 @@ function createResolvedModuleWithFailedLookupLocations( failedLookupLocations: initializeResolutionField(failedLookupLocations), affectingLocations: initializeResolutionField(affectingLocations), resolutionDiagnostics: initializeResolutionField(diagnostics), + legacyResult, }; } function initializeResolutionField(value: T[]): T[] | undefined { @@ -1665,12 +1667,30 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa const priorityExtensions = extensions & (Extensions.TypeScript | Extensions.Declaration); const secondaryExtensions = extensions & ~(Extensions.TypeScript | Extensions.Declaration); result = - priorityExtensions && tryResolve(priorityExtensions) || - secondaryExtensions && tryResolve(secondaryExtensions) || + priorityExtensions && tryResolve(priorityExtensions, state) || + secondaryExtensions && tryResolve(secondaryExtensions, state) || undefined; } else { - result = tryResolve(extensions); + result = tryResolve(extensions, state); + } + + // For non-relative names that failed to resolve in modes that look up an "import" condition in package.json "exports", + // try again with "exports" disabled to try to detect if this is likely a configuration error in a dependency's package.json. + let legacyResult; + if (!result && !isConfigLookup && !isExternalModuleNameRelative(moduleName) && features & NodeResolutionFeatures.Exports && conditions.indexOf("import") > -1) { + traceIfEnabled(state, Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update); + const diagnosticState = { + ...state, + features: state.features & ~NodeResolutionFeatures.Exports, + failedLookupLocations: [], + affectingLocations: [], + reportDiagnostic: noop, + }; + const diagnosticResult = tryResolve(extensions & (Extensions.TypeScript | Extensions.Declaration), diagnosticState); + if (diagnosticResult?.value?.isExternalLibraryImport) { + legacyResult = diagnosticResult.value.resolved.path; + } } return createResolvedModuleWithFailedLookupLocations( @@ -1679,10 +1699,11 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa failedLookupLocations, affectingLocations, diagnostics, - state.resultFromCache + state.resultFromCache, + legacyResult, ); - function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> { + function tryResolve(extensions: Extensions, state: ModuleResolutionState): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> { const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ true); const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, state); if (resolved) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 44a716a516f7a..2663d678c3d50 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7605,6 +7605,8 @@ export interface ResolvedModuleWithFailedLookupLocations { affectingLocations?: string[]; /** @internal */ resolutionDiagnostics?: Diagnostic[] + /** @internal */ + legacyResult?: string; } export interface ResolvedTypeReferenceDirective { diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt index 22d2482ced9ae..aa450c5fc0c6a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt @@ -8,7 +8,9 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` /main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. !!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -83,10 +85,12 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. +!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/yep"; import {} from "exports-and-types-versions/versioned-yep"; import {} from "exports-and-types-versions/versioned-nah"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. +!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "just-types-versions/foo"; \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json index 8c7abd981db3c..ab46ab33214e3 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json @@ -110,6 +110,16 @@ "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Export specifier './nope' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/nope' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'nope'.", + "Module name 'nope', matched pattern 'nope'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/nope' was not resolved. ========", "======== Resolving module 'exports-and-types-versions/yep' from '/main.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -145,6 +155,15 @@ "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Saw non-matching condition 'types@<4'.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'versioned-nah'.", + "Module name 'versioned-nah', matched pattern 'versioned-nah'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt index 22d2482ced9ae..aa450c5fc0c6a 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt @@ -8,7 +8,9 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` /main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. !!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -83,10 +85,12 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. +!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/yep"; import {} from "exports-and-types-versions/versioned-yep"; import {} from "exports-and-types-versions/versioned-nah"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. +!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "just-types-versions/foo"; \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json index 017892d356c35..7274f2bc1a95b 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json @@ -110,6 +110,16 @@ "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Export specifier './nope' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/nope' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'nope'.", + "Module name 'nope', matched pattern 'nope'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/nope' was not resolved. ========", "======== Resolving module 'exports-and-types-versions/yep' from '/main.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -145,6 +155,15 @@ "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Saw non-matching condition 'types@<4'.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'versioned-nah'.", + "Module name 'versioned-nah', matched pattern 'versioned-nah'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", diff --git a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt index 568ce306b98fd..2fef133f536b8 100644 --- a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt @@ -1,5 +1,6 @@ error TS2468: Cannot find global value 'Promise'. tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. + There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. tests/cases/conformance/node/index.ts(3,19): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. @@ -10,6 +11,7 @@ tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call import { Thing } from "inner/other.js"; // should fail ~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. +!!! error TS2307: There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. export const a = (await import("inner")).x(); ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. diff --git a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt index 568ce306b98fd..2fef133f536b8 100644 --- a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt @@ -1,5 +1,6 @@ error TS2468: Cannot find global value 'Promise'. tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. + There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. tests/cases/conformance/node/index.ts(3,19): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. @@ -10,6 +11,7 @@ tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call import { Thing } from "inner/other.js"; // should fail ~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. +!!! error TS2307: There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. export const a = (await import("inner")).x(); ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. From fd1ad49ca680dceb5f69a173c20ea1d2e8a1b4b4 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 9 Jan 2023 16:56:25 -0800 Subject: [PATCH 2/5] Add test and fix implementation --- src/compiler/checker.ts | 65 +++++-------- src/compiler/moduleNameResolver.ts | 11 ++- ...stic1(moduleresolution=bundler).errors.txt | 96 +++++++++++++++++++ ...stic1(moduleresolution=bundler).trace.json | 93 ++++++++++++++++++ ...ostic1(moduleresolution=node16).errors.txt | 96 +++++++++++++++++++ ...ostic1(moduleresolution=node16).trace.json | 96 +++++++++++++++++++ .../resolvesWithoutExportsDiagnostic1.ts | 66 +++++++++++++ 7 files changed, 482 insertions(+), 41 deletions(-) create mode 100644 tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt create mode 100644 tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json create mode 100644 tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt create mode 100644 tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json create mode 100644 tests/cases/conformance/moduleResolution/resolvesWithoutExportsDiagnostic1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e64a81a19b54a..07e2f1d573711 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -311,7 +311,6 @@ import { getOwnKeys, getParameterSymbolFromJSDoc, getParseTreeNode, - getPathComponents, getPropertyAssignmentAliasLikeExpression, getPropertyNameForPropertyNameNode, getResolutionDiagnostic, @@ -4767,7 +4766,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (sourceFile.symbol) { if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) { - errorOnImplicitAnyModule(/*isError*/ false, errorNode, resolvedModule, moduleReference); + errorOnImplicitAnyModule(/*isError*/ false, errorNode, currentSourceFile, mode, resolvedModule, moduleReference); } if (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext) { const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration); @@ -4855,7 +4854,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(errorNode, diag, moduleReference, resolvedModule!.resolvedFileName); } else { - errorOnImplicitAnyModule(/*isError*/ noImplicitAny && !!moduleNotFoundError, errorNode, resolvedModule!, moduleReference); + errorOnImplicitAnyModule(/*isError*/ noImplicitAny && !!moduleNotFoundError, errorNode, currentSourceFile, mode, resolvedModule!, moduleReference); } // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first. return undefined; @@ -4901,27 +4900,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } else { - const legacyResult = currentSourceFile.resolvedModules?.get(moduleReference, mode)?.legacyResult; - if (legacyResult) { - const isInTypesScope = legacyResult.indexOf(nodeModulesPathPart + "@types/") > -1; - const moduleNameParts = getPathComponents(moduleReference); - moduleNameParts.shift(); // Empty string for nonrelative module name - if (moduleNameParts.length > 1 && moduleNameParts[0] === "@types") { - moduleNameParts.shift(); - } - const isScopedLibrary = moduleNameParts.length > 1 && startsWith(moduleNameParts[0], "@"); - const libraryName = isScopedLibrary ? `${moduleNameParts[0]}/${moduleNameParts[1]}` : moduleNameParts[0]; - const details = chainDiagnosticMessages( - /*details*/ undefined, - Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json, - legacyResult, - isInTypesScope ? `@types/${mangleScopedPackageName(libraryName)}` : libraryName - ); - diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, chainDiagnosticMessages(details, moduleNotFoundError, moduleReference))); - } - else { - error(errorNode, moduleNotFoundError, moduleReference); - } + error(errorNode, moduleNotFoundError, moduleReference); } } } @@ -4945,25 +4924,33 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void { - const errorInfo = !isExternalModuleNameRelative(moduleReference) && packageId - ? typesPackageExists(packageId.name) + function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, sourceFile: SourceFile, mode: ResolutionMode, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void { + let errorInfo; + if (!isExternalModuleNameRelative(moduleReference) && packageId) { + const legacyResult = sourceFile.resolvedModules?.get(moduleReference, mode)?.legacyResult; + errorInfo = legacyResult ? chainDiagnosticMessages( /*details*/ undefined, - Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1, - packageId.name, mangleScopedPackageName(packageId.name)) - : packageBundlesTypes(packageId.name) + Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json, + legacyResult, + legacyResult.indexOf(nodeModulesPathPart + "@types/") > -1 ? `@types/${mangleScopedPackageName(packageId.name)}` : packageId.name) + : typesPackageExists(packageId.name) ? chainDiagnosticMessages( /*details*/ undefined, - Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1, - packageId.name, - moduleReference) - : chainDiagnosticMessages( - /*details*/ undefined, - Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0, - moduleReference, - mangleScopedPackageName(packageId.name)) - : undefined; + Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1, + packageId.name, mangleScopedPackageName(packageId.name)) + : packageBundlesTypes(packageId.name) + ? chainDiagnosticMessages( + /*details*/ undefined, + Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1, + packageId.name, + moduleReference) + : chainDiagnosticMessages( + /*details*/ undefined, + Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0, + moduleReference, + mangleScopedPackageName(packageId.name)); + } errorOrSuggestion(isError, errorNode, chainDiagnosticMessages( errorInfo, Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 909863d3653f7..0b03f4fedb2f3 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1675,10 +1675,17 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa result = tryResolve(extensions, state); } - // For non-relative names that failed to resolve in modes that look up an "import" condition in package.json "exports", + // For non-relative names that resolved to JS but no types in modes that look up an "import" condition in package.json "exports", // try again with "exports" disabled to try to detect if this is likely a configuration error in a dependency's package.json. let legacyResult; - if (!result && !isConfigLookup && !isExternalModuleNameRelative(moduleName) && features & NodeResolutionFeatures.Exports && conditions.indexOf("import") > -1) { + if (result?.value?.isExternalLibraryImport + && !isConfigLookup + && extensions & (Extensions.TypeScript | Extensions.Declaration) + && features & NodeResolutionFeatures.Exports + && !isExternalModuleNameRelative(moduleName) + && !extensionIsOk(Extensions.TypeScript | Extensions.Declaration, result.value.resolved.extension) + && conditions.indexOf("import") > -1 + ) { traceIfEnabled(state, Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update); const diagnosticState = { ...state, diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt new file mode 100644 index 0000000000000..ef8ea52f327c4 --- /dev/null +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt @@ -0,0 +1,96 @@ +error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/bar/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/foo/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +/index.mts(1,21): error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. + There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. +/index.mts(2,21): error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. + There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. + + +!!! error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/bar/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/foo/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +==== /node_modules/foo/package.json (0 errors) ==== + { + "name": "foo", + "version": "1.0.0", + "main": "index.js", + "types": "index.d.ts", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } + } + +==== /node_modules/foo/index.js (0 errors) ==== + module.exports = { foo: 1 }; + +==== /node_modules/foo/index.mjs (0 errors) ==== + export const foo = 1; + +==== /node_modules/foo/index.d.ts (0 errors) ==== + export declare const foo: number; + +==== /node_modules/@types/bar/package.json (0 errors) ==== + { + "name": "@types/bar", + "version": "1.0.0", + "types": "index.d.ts", + "exports": { + ".": { + "require": "./index.d.ts" + } + } + } + +==== /node_modules/@types/bar/index.d.ts (0 errors) ==== + export declare const bar: number; + +==== /node_modules/bar/package.json (0 errors) ==== + { + "name": "bar", + "version": "1.0.0", + "main": "index.js", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } + } + +==== /node_modules/bar/index.js (0 errors) ==== + module.exports = { bar: 1 }; + +==== /node_modules/bar/index.mjs (0 errors) ==== + export const bar = 1; + +==== /index.mts (2 errors) ==== + import { foo } from "foo"; + ~~~~~ +!!! error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. +!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. + import { bar } from "bar"; + ~~~~~ +!!! error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. +!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. \ No newline at end of file diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json new file mode 100644 index 0000000000000..2859c27f86107 --- /dev/null +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json @@ -0,0 +1,93 @@ +[ + "======== Resolving module 'foo' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Bundler'.", + "File '/package.json' does not exist.", + "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", + "Found 'package.json' at '/node_modules/foo/package.json'.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/foo/index.mts' does not exist.", + "File '/node_modules/foo/index.d.mts' does not exist.", + "Saw non-matching condition 'require'.", + "File '/node_modules/@types/foo.d.ts' does not exist.", + "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/foo/index.mjs' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.mjs', result '/node_modules/foo/index.mjs'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "File '/node_modules/foo.ts' does not exist.", + "File '/node_modules/foo.tsx' does not exist.", + "File '/node_modules/foo.d.ts' does not exist.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/foo/index.d.ts'.", + "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.d.ts', result '/node_modules/foo/index.d.ts'.", + "======== Module name 'foo' was successfully resolved to '/node_modules/foo/index.mjs' with Package ID 'foo/index.mjs@1.0.0'. ========", + "======== Resolving module 'bar' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Bundler'.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", + "Found 'package.json' at '/node_modules/bar/package.json'.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/bar/index.mts' does not exist.", + "File '/node_modules/bar/index.d.mts' does not exist.", + "Saw non-matching condition 'require'.", + "Found 'package.json' at '/node_modules/@types/bar/package.json'.", + "Saw non-matching condition 'require'.", + "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/bar/index.mjs' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/index.mjs', result '/node_modules/bar/index.mjs'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "File '/node_modules/bar.ts' does not exist.", + "File '/node_modules/bar.tsx' does not exist.", + "File '/node_modules/bar.d.ts' does not exist.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' does not have a 'types' field.", + "'package.json' has 'main' field 'index.js' that references '/node_modules/bar/index.js'.", + "File '/node_modules/bar/index.js' exist - use it as a name resolution result.", + "File '/node_modules/bar/index.js' has an unsupported extension, so skipping it.", + "Loading module as file / folder, candidate module location '/node_modules/bar/index.js', target file types: TypeScript, Declaration.", + "File name '/node_modules/bar/index.js' has a '.js' extension - stripping it.", + "File '/node_modules/bar/index.ts' does not exist.", + "File '/node_modules/bar/index.tsx' does not exist.", + "File '/node_modules/bar/index.d.ts' does not exist.", + "File '/node_modules/bar/index.js.ts' does not exist.", + "File '/node_modules/bar/index.js.tsx' does not exist.", + "File '/node_modules/bar/index.js.d.ts' does not exist.", + "Directory '/node_modules/bar/index.js' does not exist, skipping all lookups in it.", + "File '/node_modules/bar/index.ts' does not exist.", + "File '/node_modules/bar/index.tsx' does not exist.", + "File '/node_modules/bar/index.d.ts' does not exist.", + "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "File '/node_modules/@types/bar.d.ts' does not exist.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/@types/bar/index.d.ts'.", + "File '/node_modules/@types/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/bar/index.d.ts', result '/node_modules/@types/bar/index.d.ts'.", + "======== Module name 'bar' was successfully resolved to '/node_modules/bar/index.mjs' with Package ID 'bar/index.mjs@1.0.0'. ========", + "======== Resolving type reference directive 'bar', containing file '__inferred type names__.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'.", + "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/@types/bar/index.d.ts'.", + "File '/node_modules/@types/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/bar/index.d.ts', result '/node_modules/@types/bar/index.d.ts'.", + "======== Type reference directive 'bar' was successfully resolved to '/node_modules/@types/bar/index.d.ts' with Package ID '@types/bar/index.d.ts@1.0.0', primary: true. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt new file mode 100644 index 0000000000000..ef8ea52f327c4 --- /dev/null +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt @@ -0,0 +1,96 @@ +error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/bar/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/foo/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? + The file is in the program because: + Root file specified for compilation +/index.mts(1,21): error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. + There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. +/index.mts(2,21): error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. + There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. + + +!!! error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/bar/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/foo/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +!!! error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you mean to enable the 'allowJs' option? +!!! error TS6504: The file is in the program because: +!!! error TS6504: Root file specified for compilation +==== /node_modules/foo/package.json (0 errors) ==== + { + "name": "foo", + "version": "1.0.0", + "main": "index.js", + "types": "index.d.ts", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } + } + +==== /node_modules/foo/index.js (0 errors) ==== + module.exports = { foo: 1 }; + +==== /node_modules/foo/index.mjs (0 errors) ==== + export const foo = 1; + +==== /node_modules/foo/index.d.ts (0 errors) ==== + export declare const foo: number; + +==== /node_modules/@types/bar/package.json (0 errors) ==== + { + "name": "@types/bar", + "version": "1.0.0", + "types": "index.d.ts", + "exports": { + ".": { + "require": "./index.d.ts" + } + } + } + +==== /node_modules/@types/bar/index.d.ts (0 errors) ==== + export declare const bar: number; + +==== /node_modules/bar/package.json (0 errors) ==== + { + "name": "bar", + "version": "1.0.0", + "main": "index.js", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } + } + +==== /node_modules/bar/index.js (0 errors) ==== + module.exports = { bar: 1 }; + +==== /node_modules/bar/index.mjs (0 errors) ==== + export const bar = 1; + +==== /index.mts (2 errors) ==== + import { foo } from "foo"; + ~~~~~ +!!! error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. +!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. + import { bar } from "bar"; + ~~~~~ +!!! error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. +!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. \ No newline at end of file diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json new file mode 100644 index 0000000000000..6d8b992bfbc76 --- /dev/null +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json @@ -0,0 +1,96 @@ +[ + "Found 'package.json' at '/node_modules/foo/package.json'.", + "Found 'package.json' at '/node_modules/@types/bar/package.json'.", + "======== Resolving module 'foo' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Node16'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist.", + "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/foo/index.mts' does not exist.", + "File '/node_modules/foo/index.d.mts' does not exist.", + "Saw non-matching condition 'require'.", + "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/foo/index.mjs' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.mjs', result '/node_modules/foo/index.mjs'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/foo/index.d.ts'.", + "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/foo/index.d.ts', result '/node_modules/foo/index.d.ts'.", + "======== Module name 'foo' was successfully resolved to '/node_modules/foo/index.mjs' with Package ID 'foo/index.mjs@1.0.0'. ========", + "======== Resolving module 'bar' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Node16'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "Found 'package.json' at '/node_modules/bar/package.json'.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/bar/index.mts' does not exist.", + "File '/node_modules/bar/index.d.mts' does not exist.", + "Saw non-matching condition 'require'.", + "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "Saw non-matching condition 'require'.", + "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './index.mjs'.", + "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/bar/index.mjs' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/bar/index.mjs', result '/node_modules/bar/index.mjs'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' does not have a 'types' field.", + "'package.json' has 'main' field 'index.js' that references '/node_modules/bar/index.js'.", + "File '/node_modules/bar/index.js' exist - use it as a name resolution result.", + "File '/node_modules/bar/index.js' has an unsupported extension, so skipping it.", + "Loading module as file / folder, candidate module location '/node_modules/bar/index.js', target file types: TypeScript, Declaration.", + "File name '/node_modules/bar/index.js' has a '.js' extension - stripping it.", + "File '/node_modules/bar/index.ts' does not exist.", + "File '/node_modules/bar/index.tsx' does not exist.", + "File '/node_modules/bar/index.d.ts' does not exist.", + "File '/node_modules/bar/index.js.ts' does not exist.", + "File '/node_modules/bar/index.js.tsx' does not exist.", + "File '/node_modules/bar/index.js.d.ts' does not exist.", + "Directory '/node_modules/bar/index.js' does not exist, skipping all lookups in it.", + "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typesVersions' field.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/@types/bar/index.d.ts'.", + "File '/node_modules/@types/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/bar/index.d.ts', result '/node_modules/@types/bar/index.d.ts'.", + "======== Module name 'bar' was successfully resolved to '/node_modules/bar/index.mjs' with Package ID 'bar/index.mjs@1.0.0'. ========", + "======== Resolving type reference directive 'bar', containing file '__inferred type names__.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'.", + "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index.d.ts' that references '/node_modules/@types/bar/index.d.ts'.", + "File '/node_modules/@types/bar/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/bar/index.d.ts', result '/node_modules/@types/bar/index.d.ts'.", + "======== Type reference directive 'bar' was successfully resolved to '/node_modules/@types/bar/index.d.ts' with Package ID '@types/bar/index.d.ts@1.0.0', primary: true. ========", + "File 'package.json' does not exist.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups." +] \ No newline at end of file diff --git a/tests/cases/conformance/moduleResolution/resolvesWithoutExportsDiagnostic1.ts b/tests/cases/conformance/moduleResolution/resolvesWithoutExportsDiagnostic1.ts new file mode 100644 index 0000000000000..d01bb47a75ca8 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/resolvesWithoutExportsDiagnostic1.ts @@ -0,0 +1,66 @@ +// @moduleResolution: bundler,node16 +// @strict: true +// @noTypesAndSymbols: true +// @noEmit: true +// @traceResolution: true + +// @Filename: /node_modules/foo/package.json +{ + "name": "foo", + "version": "1.0.0", + "main": "index.js", + "types": "index.d.ts", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } +} + +// @Filename: /node_modules/foo/index.js +module.exports = { foo: 1 }; + +// @Filename: /node_modules/foo/index.mjs +export const foo = 1; + +// @Filename: /node_modules/foo/index.d.ts +export declare const foo: number; + +// @Filename: /node_modules/@types/bar/package.json +{ + "name": "@types/bar", + "version": "1.0.0", + "types": "index.d.ts", + "exports": { + ".": { + "require": "./index.d.ts" + } + } +} + +// @Filename: /node_modules/@types/bar/index.d.ts +export declare const bar: number; + +// @Filename: /node_modules/bar/package.json +{ + "name": "bar", + "version": "1.0.0", + "main": "index.js", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } +} + +// @Filename: /node_modules/bar/index.js +module.exports = { bar: 1 }; + +// @Filename: /node_modules/bar/index.mjs +export const bar = 1; + +// @Filename: /index.mts +import { foo } from "foo"; +import { bar } from "bar"; \ No newline at end of file From 71d356c8ce52f09868b2881962d38b53dadd260c Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 10 Jan 2023 15:50:03 -0800 Subject: [PATCH 3/5] Update baselines --- ...cksTypesVersions(module=node16).errors.txt | 8 ++--- ...cksTypesVersions(module=node16).trace.json | 29 +++++++------------ ...sTypesVersions(module=nodenext).errors.txt | 8 ++--- ...sTypesVersions(module=nodenext).trace.json | 29 +++++++------------ ...rationConditions(module=node16).errors.txt | 2 -- ...tionConditions(module=nodenext).errors.txt | 2 -- 6 files changed, 24 insertions(+), 54 deletions(-) diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt index aa450c5fc0c6a..adb07aef3e821 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt @@ -6,11 +6,9 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. - If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` -/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. +/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. - There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. !!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -81,16 +79,14 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/foo"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. -!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` +!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. -!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/yep"; import {} from "exports-and-types-versions/versioned-yep"; import {} from "exports-and-types-versions/versioned-nah"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. -!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "just-types-versions/foo"; \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json index ab46ab33214e3..d0aae2ef9523b 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json @@ -99,6 +99,16 @@ "File name '/node_modules/exports-and-types-versions/dist/foo.js' has a '.js' extension - stripping it.", "File '/node_modules/exports-and-types-versions/dist/foo.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/exports-and-types-versions/dist/foo.js', result '/node_modules/exports-and-types-versions/dist/foo.js'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'foo'.", + "Module name 'foo', matched pattern 'foo'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/foo' was successfully resolved to '/node_modules/exports-and-types-versions/dist/foo.js' with Package ID 'exports-and-types-versions/dist/foo.js@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/nope' from '/main.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -110,16 +120,6 @@ "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Export specifier './nope' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", - "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", - "File '/package.json' does not exist according to earlier cached lookups.", - "Loading module 'exports-and-types-versions/nope' from 'node_modules' folder, target file types: TypeScript, Declaration.", - "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'nope'.", - "Module name 'nope', matched pattern 'nope'.", - "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", - "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/nope' was not resolved. ========", "======== Resolving module 'exports-and-types-versions/yep' from '/main.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -155,15 +155,6 @@ "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Saw non-matching condition 'types@<4'.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", - "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", - "File '/package.json' does not exist according to earlier cached lookups.", - "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, Declaration.", - "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", - "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'versioned-nah'.", - "Module name 'versioned-nah', matched pattern 'versioned-nah'.", - "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", - "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt index aa450c5fc0c6a..adb07aef3e821 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt @@ -6,11 +6,9 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. - If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` -/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. +/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. - There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. !!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -81,16 +79,14 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/foo"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. -!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';` +!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. -!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "exports-and-types-versions/yep"; import {} from "exports-and-types-versions/versioned-yep"; import {} from "exports-and-types-versions/versioned-nah"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. -!!! error TS2307: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. import {} from "just-types-versions/foo"; \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json index 7274f2bc1a95b..de93053530308 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json @@ -99,6 +99,16 @@ "File name '/node_modules/exports-and-types-versions/dist/foo.js' has a '.js' extension - stripping it.", "File '/node_modules/exports-and-types-versions/dist/foo.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/exports-and-types-versions/dist/foo.js', result '/node_modules/exports-and-types-versions/dist/foo.js'.", + "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", + "File '/package.json' does not exist according to earlier cached lookups.", + "Loading module 'exports-and-types-versions/foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", + "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", + "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'foo'.", + "Module name 'foo', matched pattern 'foo'.", + "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", + "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/foo' was successfully resolved to '/node_modules/exports-and-types-versions/dist/foo.js' with Package ID 'exports-and-types-versions/dist/foo.js@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/nope' from '/main.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -110,16 +120,6 @@ "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Export specifier './nope' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", - "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", - "File '/package.json' does not exist according to earlier cached lookups.", - "Loading module 'exports-and-types-versions/nope' from 'node_modules' folder, target file types: TypeScript, Declaration.", - "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'nope'.", - "Module name 'nope', matched pattern 'nope'.", - "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", - "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/nope' was not resolved. ========", "======== Resolving module 'exports-and-types-versions/yep' from '/main.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -155,15 +155,6 @@ "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", "Saw non-matching condition 'types@<4'.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", - "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", - "File '/package.json' does not exist according to earlier cached lookups.", - "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, Declaration.", - "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", - "'package.json' has a 'typesVersions' entry '*' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'versioned-nah'.", - "Module name 'versioned-nah', matched pattern 'versioned-nah'.", - "Trying substitution './types/foo.d.ts', candidate module location: './types/foo.d.ts'.", - "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exist - use it as a name resolution result.", - "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", diff --git a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt index 2fef133f536b8..568ce306b98fd 100644 --- a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=node16).errors.txt @@ -1,6 +1,5 @@ error TS2468: Cannot find global value 'Promise'. tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. - There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. tests/cases/conformance/node/index.ts(3,19): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. @@ -11,7 +10,6 @@ tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call import { Thing } from "inner/other.js"; // should fail ~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. -!!! error TS2307: There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. export const a = (await import("inner")).x(); ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. diff --git a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt index 2fef133f536b8..568ce306b98fd 100644 --- a/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsSpecifierGenerationConditions(module=nodenext).errors.txt @@ -1,6 +1,5 @@ error TS2468: Cannot find global value 'Promise'. tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. - There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. tests/cases/conformance/node/index.ts(3,19): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option. @@ -11,7 +10,6 @@ tests/cases/conformance/node/index.ts(3,25): error TS2712: A dynamic import call import { Thing } from "inner/other.js"; // should fail ~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations. -!!! error TS2307: There are types at 'tests/cases/conformance/node/node_modules/inner/other.d.ts', but this result could not be resolved when respecting package.json "exports". The 'inner' library may need to update its package.json. export const a = (await import("inner")).x(); ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. From 816719da14b795aeec71f58b72896e95025a379f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 10 Jan 2023 16:07:06 -0800 Subject: [PATCH 4/5] Update type from merge --- src/compiler/moduleNameResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index a813494693e79..88bf1712cc95a 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2300,7 +2300,7 @@ function resolvedIfExtensionMatches(extensions: Extensions, path: string, resolv } /** True if `extension` is one of the supported `extensions`. */ -function extensionIsOk(extensions: Extensions, extension: Extension): boolean { +function extensionIsOk(extensions: Extensions, extension: string): boolean { return extensions & Extensions.JavaScript && (extension === Extension.Js || extension === Extension.Jsx || extension === Extension.Mjs || extension === Extension.Cjs) || extensions & Extensions.TypeScript && (extension === Extension.Ts || extension === Extension.Tsx || extension === Extension.Mts || extension === Extension.Cts) || extensions & Extensions.Declaration && (extension === Extension.Dts || extension === Extension.Dmts || extension === Extension.Dcts) From 8d8907f9cc5152126921f40bab42eb9d086e95a4 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 12 Jan 2023 16:05:08 -0800 Subject: [PATCH 5/5] Tweak text --- src/compiler/checker.ts | 10 +++++----- src/compiler/diagnosticMessages.json | 2 +- src/compiler/moduleNameResolver.ts | 2 +- src/compiler/types.ts | 8 ++++++-- ...xportsBlocksTypesVersions(module=node16).errors.txt | 4 ++-- ...ortsBlocksTypesVersions(module=nodenext).errors.txt | 4 ++-- ...rtsDiagnostic1(moduleresolution=bundler).errors.txt | 8 ++++---- ...ortsDiagnostic1(moduleresolution=node16).errors.txt | 8 ++++---- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 031e924b04819..9b379adbdc9da 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4929,13 +4929,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function errorOnImplicitAnyModule(isError: boolean, errorNode: Node, sourceFile: SourceFile, mode: ResolutionMode, { packageId, resolvedFileName }: ResolvedModuleFull, moduleReference: string): void { let errorInfo; if (!isExternalModuleNameRelative(moduleReference) && packageId) { - const legacyResult = sourceFile.resolvedModules?.get(moduleReference, mode)?.legacyResult; - errorInfo = legacyResult + const node10Result = sourceFile.resolvedModules?.get(moduleReference, mode)?.node10Result; + errorInfo = node10Result ? chainDiagnosticMessages( /*details*/ undefined, - Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json, - legacyResult, - legacyResult.indexOf(nodeModulesPathPart + "@types/") > -1 ? `@types/${mangleScopedPackageName(packageId.name)}` : packageId.name) + Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json_or_typings, + node10Result, + node10Result.indexOf(nodeModulesPathPart + "@types/") > -1 ? `@types/${mangleScopedPackageName(packageId.name)}` : packageId.name) : typesPackageExists(packageId.name) ? chainDiagnosticMessages( /*details*/ undefined, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9e6c6dca7fa35..377bc39a74d82 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5239,7 +5239,7 @@ "category": "Message", "code": 6277 }, - "There are types at '{0}', but this result could not be resolved when respecting package.json \"exports\". The '{1}' library may need to update its package.json.": { + "There are types at '{0}', but this result could not be resolved when respecting package.json \"exports\". The '{1}' library may need to update its package.json or typings.": { "category": "Message", "code": 6278 }, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index d7f9878a13404..0d66245a58f41 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -233,7 +233,7 @@ function createResolvedModuleWithFailedLookupLocations( failedLookupLocations: initializeResolutionField(failedLookupLocations), affectingLocations: initializeResolutionField(affectingLocations), resolutionDiagnostics: initializeResolutionField(diagnostics), - legacyResult, + node10Result: legacyResult, }; } function initializeResolutionField(value: T[]): T[] | undefined { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4b37d177bdc1c..a3f2be654b158 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7606,8 +7606,12 @@ export interface ResolvedModuleWithFailedLookupLocations { affectingLocations?: string[]; /** @internal */ resolutionDiagnostics?: Diagnostic[] - /** @internal */ - legacyResult?: string; + /** + * @internal + * Used to issue a diagnostic if typings for a non-relative import couldn't be found + * while respecting package.json `exports`, but were found when disabling `exports`. + */ + node10Result?: string; } export interface ResolvedTypeReferenceDirective { diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt index adb07aef3e821..a0ed330173ed8 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).errors.txt @@ -6,7 +6,7 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. - There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json or typings. /main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. @@ -79,7 +79,7 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/foo"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. +!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json or typings. import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt index adb07aef3e821..a0ed330173ed8 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).errors.txt @@ -6,7 +6,7 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J /main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. /main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. - There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. + There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json or typings. /main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. /main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations. @@ -79,7 +79,7 @@ error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a J import {} from "exports-and-types-versions/foo"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json. +!!! error TS7016: There are types at '/node_modules/exports-and-types-versions/types/foo.d.ts', but this result could not be resolved when respecting package.json "exports". The 'exports-and-types-versions' library may need to update its package.json or typings. import {} from "exports-and-types-versions/nope"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations. diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt index ef8ea52f327c4..fe904ca69530b 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).errors.txt @@ -11,9 +11,9 @@ error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you m The file is in the program because: Root file specified for compilation /index.mts(1,21): error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. - There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. + There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json or typings. /index.mts(2,21): error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. - There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. + There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json or typings. !!! error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -89,8 +89,8 @@ error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you m import { foo } from "foo"; ~~~~~ !!! error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. +!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json or typings. import { bar } from "bar"; ~~~~~ !!! error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. \ No newline at end of file +!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json or typings. \ No newline at end of file diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt index ef8ea52f327c4..fe904ca69530b 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).errors.txt @@ -11,9 +11,9 @@ error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you m The file is in the program because: Root file specified for compilation /index.mts(1,21): error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. - There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. + There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json or typings. /index.mts(2,21): error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. - There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. + There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json or typings. !!! error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? @@ -89,8 +89,8 @@ error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you m import { foo } from "foo"; ~~~~~ !!! error TS7016: Could not find a declaration file for module 'foo'. '/node_modules/foo/index.mjs' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json. +!!! error TS7016: There are types at '/node_modules/foo/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'foo' library may need to update its package.json or typings. import { bar } from "bar"; ~~~~~ !!! error TS7016: Could not find a declaration file for module 'bar'. '/node_modules/bar/index.mjs' implicitly has an 'any' type. -!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json. \ No newline at end of file +!!! error TS7016: There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json or typings. \ No newline at end of file