Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-extractor] building with TS 5.6.2 causes error on wildcard import #4919

Closed
wmertens opened this issue Sep 11, 2024 · 8 comments · Fixed by #4973
Closed

[api-extractor] building with TS 5.6.2 causes error on wildcard import #4919

wmertens opened this issue Sep 11, 2024 · 8 comments · Fixed by #4973

Comments

@wmertens
Copy link

Summary

Trying to upgrade TS from 5.4.5 to 5.6.2

Somehow this causes api extractor to fail. I tried with the latest version as well as an older version.

Repro steps

  • upgrade qwik to latest tsc
  • pnpm api.update
❌ Error: Internal Error: getResolvedModule() could not resolve module name "./render/jsx/types/jsx-generated"
/home/wmertens/Projects/qwik/dist-dev/dts-out/packages/qwik/src/core/index.d.ts:16:1

You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.
    at ExportAnalyzer._fetchSpecifierAstModule (/home/wmertens/Projects/qwik/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@microsoft/api-extractor/src/analyzer/ExportAnalyzer.ts:924:13)
    at ExportAnalyzer.fetchAstModuleFromSourceFile (/home/wmertens/Projects/qwik/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@microsoft/api-extractor/src/analyzer/ExportAnalyzer.ts:159:72)
    at AstSymbolTable.fetchAstModuleFromWorkingPackage (/home/wmertens/Projects/qwik/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@microsoft/api-extractor/src/analyzer/AstSymbolTable.ts:121:33)
    at Collector.analyze (/home/wmertens/Projects/qwik/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@microsoft/api-extractor/src/collector/Collector.ts:294:27)
    at Function.invoke (/home/wmertens/Projects/qwik/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@microsoft/api-extractor/src/api/Extractor.ts:261:15)
    at createTypesApi (/home/wmertens/Projects/qwik/scripts/api.ts:214:28)
    at apiExtractorQwik (/home/wmertens/Projects/qwik/scripts/api.ts:14:3)
    at build (/home/wmertens/Projects/qwik/scripts/build.ts:93:13)
 Error: Error: Internal Error: getResolvedModule() could not resolve module name "./render/jsx/types/jsx-generated"
/home/wmertens/Projects/qwik/dist-dev/dts-out/packages/qwik/src/core/index.d.ts:16:1

See https://github.com/QwikDev/qwik/actions/runs/10813753964/job/29998536883?pr=6874#step:6:536

Details

It's failing on

export type * from './render/jsx/types/jsx-generated';

But there's nothing special in the file it imports

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.47.8
Operating system? Linux
API Extractor scenario? reporting + docs -->
Would you consider contributing a PR? Yes but need help
TypeScript compiler version? 5.6.2
Node.js version (node -v)? 20.14.0
@JoshuaKGoldberg
Copy link

We also have a reproduction over in typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/pull/9972/files.

@octogonz-dev
Copy link

Thanks for providing a repro. I am on a business trip but will take a look when I get a chance.

@JoshuaKGoldberg
Copy link

@octogonz-dev sorry for bothering you, but this is blocking us in typescript-ealint - is there anything we can do to help?

@josundt
Copy link

josundt commented Oct 14, 2024

Will this be fixed soon? Looks like typescript-eslint cannot support TypeScript 5.6 until this has been fixed.

@jakebailey
Copy link
Member

jakebailey commented Oct 14, 2024

microsoft/TypeScript#58825 was the PR which made api-extractor stop working; api-extractor reaches into TS internals, so this isn't super surprising.

$ every-ts switch a9139bfdfea154dfa9cc97f465c933ee02b3fcfa~1
$ yarn build

api-extractor 7.47.8  - https://api-extractor.com/

Using configuration from ./api-extractor.json
Analysis will use the bundled TypeScript version 5.6.0-dev

API Extractor completed successfully

$ every-ts switch a9139bfdfea154dfa9cc97f465c933ee02b3fcfa
$ yarn build                                              

api-extractor 7.47.8  - https://api-extractor.com/

Using configuration from ./api-extractor.json
Analysis will use the bundled TypeScript version 5.6.0-dev

ERROR: Internal Error: getResolvedModule() could not resolve module name "./ast-node-types"
/home/jabaile/work/TypeScript-eslint/packages/ast-spec/dist/index.d.ts:1:1

You have encountered a software defect. Please consider reporting the issue to the maintainers of this application.

I have not debugged past this.

@jakebailey
Copy link
Member

getModeForUsageLocation is supposed to take compiler options, but api-extractor is not passing them in.

This diff was enough to make ts-eslint not crash:

diff --git a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts
index 5268cc8eb1..d1fdc103f2 100644
--- a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts
+++ b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts
@@ -265,7 +265,7 @@ export class ExportAnalyzer {
       : importOrExportDeclaration.moduleSpecifier;
     const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined =
       specifier && ts.isStringLiteralLike(specifier)
-        ? TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier)
+        ? TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier, this._program.getCompilerOptions())
         : undefined;
 
     const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
@@ -905,7 +905,8 @@ export class ExportAnalyzer {
       ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier)
         ? TypeScriptInternals.getModeForUsageLocation(
             importOrExportDeclaration.getSourceFile(),
-            importOrExportDeclaration.moduleSpecifier
+            importOrExportDeclaration.moduleSpecifier,
+            this._program.getCompilerOptions()
           )
         : undefined;
     const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(
diff --git a/apps/api-extractor/src/analyzer/TypeScriptInternals.ts b/apps/api-extractor/src/analyzer/TypeScriptInternals.ts
index eeb8e1b4df..6c48447cef 100644
--- a/apps/api-extractor/src/analyzer/TypeScriptInternals.ts
+++ b/apps/api-extractor/src/analyzer/TypeScriptInternals.ts
@@ -102,12 +102,13 @@ export class TypeScriptInternals {
    */
   public static getModeForUsageLocation(
     file: { impliedNodeFormat?: ts.SourceFile['impliedNodeFormat'] },
-    usage: ts.StringLiteralLike | undefined
+    usage: ts.StringLiteralLike | undefined,
+    compilerOptions: ts.CompilerOptions
   ): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined {
     // Compiler internal:
     // https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/program.ts#L568
 
-    return (ts as any).getModeForUsageLocation?.(file, usage);
+    return (ts as any).getModeForUsageLocation?.(file, usage, compilerOptions);
   }
 
   /**

I have not validated that things still work.

I'll also note that getModeForUsageLocation is a public function; there's no reason to as any anything here as that would have shown the problem earlier.

@jakebailey
Copy link
Member

Sent #4973

@github-project-automation github-project-automation bot moved this from Needs triage to Closed in Bug Triage Oct 14, 2024
@JoshuaKGoldberg
Copy link

❤ thanks @jakebailey!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants