Skip to content

"Debug Failure. False expression." when using default export from js fileΒ #60692

Description

πŸ”Ž Search Terms

debug failure false expression export default composite allowjs js

πŸ•— Version & Regression Information

  • This changed between versions 5.6.2 and 5.7.2

⏯ Playground Link

https://stackblitz.com/edit/ts-false-expression-tqxlxy?file=tsconfig.json,package.json

πŸ’» Code

// In a JS file
export default console; 

The error also seems to happen if you replace console with anything from globalThis (screen, scroll, fetch, etc.)

TSConfig.json:

    "composite": true,
    "allowJs": true,

πŸ™ Actual behavior

Running tsc results in this error:

> tsc

Error: Debug Failure. False expression.
    at Object.isUndefinedIdentifierExpression (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:50211:15)
    at typeFromExpression (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:132377:22)
    at serializeTypeOfExpression (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:132107:20)
    at Object.serializeTypeOfDeclaration (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:132131:16)
    at serializeTypeForDeclaration (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:52640:41)
    at serializeMaybeAliasAssignment (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:54015:19)
    at serializeAsAlias (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:53899:13)
    at serializeSymbolWorker (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:53255:11)
    at serializeSymbol (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:53119:11)
    at eval (/home/projects/ts-false-expression-tqxlxy/node_modules/typescript/lib/_tsc.js:53089:11)

Node.js v18.20.3

πŸ™‚ Expected behavior

No Error :-)

Additional information about the issue

I see this both locally and in stackblitz. I don't know how to reproduce in the playground because it only seems to happen when using a JS file.

This does not cause an error:

const thing = console;
export default thing;

Activity

  1. nmain commented on Dec 5, 2024

    @nmain

    The playground can be set to Javascript, and does seem to get the same error: https://www.typescriptlang.org/play/?filetype=js#code/KYDwDg9gTgLgBAE2AMwIYFcA28DuBLAOwQhwG4AoIA

    tsMode.js:8 Uncaught (in promise) Error: Debug Failure. False expression.
        at Object.isUndefinedIdentifierExpression (tsWorker.js:344:245998)
        at Z (tsWorker.js:362:12320)
        at h (tsWorker.js:362:8628)
        at Object._ [as serializeTypeOfDeclaration] (tsWorker.js:362:8889)
        at g0 (tsWorker.js:348:14998)
        at hM (tsWorker.js:351:9451)
        at y0 (tsWorker.js:351:8083)
        at jr (tsWorker.js:348:24089)
        at Vn (tsWorker.js:348:21713)
        at tsWorker.js:348:21375
    
  2. boneskull commented on Feb 12, 2025

    @boneskull
    Contributor

    via bisect, I've determined the problem was introduced in #59282 and is likely in src/compiler/expressionToTypeNode.ts somewhere. unfortunately, that's about as far as I can get. cc Titian Cernicova-Dragomir (@dragomirtitian)

  3. boneskull commented on Feb 12, 2025

    @boneskull
    Contributor

    OK, I lied, I got closer. The switch in isExpressionNode is failing here:

    case SyntaxKind.Identifier:
    if (node.parent.kind === SyntaxKind.TypeQuery || isJSDocLinkLike(node.parent) || isJSDocNameReference(node.parent) || isJSDocMemberName(node.parent) || isJSXTagName(node)) {
    return true;
    }
    // falls through

    Given:

    export default baz

    where baz was not defined anywhere in the module (so it must be globalThis.baz), we find that baz is an Identifier, and its parent is an ExportAssignment (default), so it does not return true here, and falls through to the bottom of the switch, returning false and failing the assertion.

  4. alebrozzo commented on Mar 14, 2025

    @alebrozzo

    I'm wondering if there will be a fix for this or should I start looking to change my own code to try to solve this? I am unable to upgrade because of this

  5. literalpie commented on Mar 14, 2025

    @literalpie
    Author

    Personally, I did a workaround. It's pretty simple since it works as long as you set the value before you export it

    // Change from: export default console;
    // To:
    const myConsole = console;
    export default myConsole;
    
  6. NotYoojun commented on Apr 2, 2025

    @NotYoojun

    I had to patch the package in order to skip this check so that my bundler can work. It's not a good idea, though.

    diff --git a/lib/typescript.js b/lib/typescript.js
    index dc0fe9a56bb4d9b08efe8b5948a60a74a4e9997b..3949bd42b5d2f120c1f1521de685164884ed1d7a 100755
    --- a/lib/typescript.js	
    +++ b/lib/typescript.js	
    @@ -55006,7 +55006,7 @@ function createTypeChecker(host) {
           },
           isOptionalParameter,
           isUndefinedIdentifierExpression(node) {
    -        Debug.assert(isExpressionNode(node));
    +        // Debug.assert(isExpressionNode(node)); // To get rid of: [!] (plugin typescript) Error: Debug Failure. False expression.
             return getSymbolAtLocation(node) === undefinedSymbol;
           },
           isEntityNameVisible(context, entityName, shouldComputeAliasToMakeVisible) {
    
  7. bolatovumar commented on Apr 4, 2025

    @bolatovumar

    I'm getting the exact same error in my code. Also began in TS 5.7

  8. boneskull commented on Apr 24, 2025

    @boneskull
    Contributor

    This was fixed in #61582 by Andrew Branch (@andrewbranch). I can reproduce in v5.8.3, but not main.

  9. locked as resolved and limited conversation to collaborators on Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions