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

"Error: Debug Failure." when building a TypeScript library that depends on another TypeScript library. #56179

Closed
zkWildfire opened this issue Oct 23, 2023 · 6 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@zkWildfire
Copy link

🔎 Search Terms

  • typescript error debug failure
  • typescript Debug.checkDefined(tryExtractTSExtension(moduleReference));
  • typescript checkDefined

A related bug report is here:
#52182

However, that bug was fixed in January 2023 and I'm seeing this issue with TypeScript v5.1.6, which released on July 5, 2023.

🕗 Version & Regression Information

  • This is a crash

⏯ Playground Link

No response

💻 Code

I've created an MCVE repo here:
https://github.com/zkWildfire/tsc-nx

The issue can be repro'd with a total of two source files (plus index.ts files). The repo is configured with a VSCode devcontainer, so hopefully it won't be a problem to repro the issue locally. Full instructions are provided in the repo's readme.

In summary, the issue occurs when importing a type from a subdirectory of a library, e.g. import { Foo } from "@mylib/foo" is fine but import { Foo } from "@mylib/foo/bar" breaks. In my MCVE, the bug appears as this error message when running nx build foo:

Compiling TypeScript files for project "foo"...
/workspaces/tsc-nx/buggy/node_modules/typescript/lib/typescript.js:48326
          const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference));

I'm relatively new to TypeScript and nx so I'm not sure if I've done something wrong with the project configuration. The change that I made to the tsconfig.base.json file was to add this line:

    "paths": {
      "@buggy/bar": ["bar/src/index.ts"],
      "@buggy/bar/lib": ["bar/src/lib/index.ts"], // <<<<<<<<<
      "@buggy/foo": ["foo/src/index.ts"]
    }

Even if that's an issue though, the TypeScript compiler should still be failing with a regular error message rather than an internal compiler check error.

🙁 Actual behavior

The TypeScript build fails due to an internal compiler debug check.

🙂 Expected behavior

The build should complete successfully.

Additional information about the issue

No response

@jakebailey
Copy link
Member

Do you have a version of this that doesn't involve nx's build system? They wrap TS so a crash like this can be caused by their code.

@zkWildfire
Copy link
Author

Hey Jake, thanks for the quick reply. I tried running npx tsc --project tsconfig.base.json on both the working and buggy projects in my repo, and that seems to work fine. Seems like the issue must be with nx then? If so, you can close this issue and I'll file a bug report with nx instead.

@jakebailey
Copy link
Member

I suspect that this is something in nx, yes, though the backtrace doesn't appear to be long enough to figure that out. The line of code above is in resolveExternalModule, and it wouldn't be surprising to me if their custom compiler host incorrectly implemented something it needed.

@jakebailey jakebailey added the External Relates to another program, environment, or user action which we cannot control. label Oct 23, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "External" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@hlolli
Copy link

hlolli commented Feb 3, 2024

I had this error coming randomly using 'nx', actually in the middle of migration to it

npx tsc --noEmit --project apps/client/tsconfig.json
/.../typescript/lib/tsc.js:1321
    throw e;
    ^

Error: Debug Failure.
    at resolveExternalModule (/.../node_modules/typescript/lib/tsc.js:46519:37)
    at resolveExternalModuleNameWorker (/.../node_modules/typescript/lib/tsc.js:46478:61)
    at resolveExternalModuleName (/.../node_modules/typescript/lib/tsc.js:46475:12)
    at getSymbolAtLocation (/.../node_modules/typescript/lib/tsc.js:81623:18)
    at Object.getSymbolAtLocation (/.../node_modules/typescript/lib/tsc.js:43355:21)
    at getReferencedFilesFromImportLiteral (/.../node_modules/typescript/lib/tsc.js:119559:28)
    at getReferencedFiles (/.../node_modules/typescript/lib/tsc.js:119570:44)
    at Object.create (/.../node_modules/typescript/lib/tsc.js:119639:31)
    at createBuilderProgramState (/.../node_modules/typescript/lib/tsc.js:119925:30)
    at createBuilderProgram (/.../node_modules/typescript/lib/tsc.js:120738:17)

not ruling out that using tsc directly is a bad idea, I don't know 'nx' properly yet

@chefalexbs
Copy link

I had this error coming randomly using 'nx', actually in the middle of migration to it

npx tsc --noEmit --project apps/client/tsconfig.json
/.../typescript/lib/tsc.js:1321
    throw e;
    ^

Error: Debug Failure.
    at resolveExternalModule (/.../node_modules/typescript/lib/tsc.js:46519:37)
    at resolveExternalModuleNameWorker (/.../node_modules/typescript/lib/tsc.js:46478:61)
    at resolveExternalModuleName (/.../node_modules/typescript/lib/tsc.js:46475:12)
    at getSymbolAtLocation (/.../node_modules/typescript/lib/tsc.js:81623:18)
    at Object.getSymbolAtLocation (/.../node_modules/typescript/lib/tsc.js:43355:21)
    at getReferencedFilesFromImportLiteral (/.../node_modules/typescript/lib/tsc.js:119559:28)
    at getReferencedFiles (/.../node_modules/typescript/lib/tsc.js:119570:44)
    at Object.create (/.../node_modules/typescript/lib/tsc.js:119639:31)
    at createBuilderProgramState (/.../node_modules/typescript/lib/tsc.js:119925:30)
    at createBuilderProgram (/.../node_modules/typescript/lib/tsc.js:120738:17)

not ruling out that using tsc directly is a bad idea, I don't know 'nx' properly yet

did you find a solution to the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

5 participants