Skip to content

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

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

Open
literalpie opened this issue Dec 5, 2024 · 7 comments
Open
Assignees
Labels
Bug A bug in TypeScript

Comments

@literalpie
Copy link

literalpie commented Dec 5, 2024

πŸ”Ž 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;
@nmain
Copy link

nmain commented Dec 5, 2024

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

@boneskull
Copy link
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 @dragomirtitian

@boneskull
Copy link
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.

@alebrozzo
Copy link

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

@literalpie
Copy link
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;

kmonahan added a commit to forumone/gesso that referenced this issue Mar 20, 2025
Error occurred any time a TSX file was edited. Related to microsoft/TypeScript#60692. TypeScript doesn't like exports of globals, even in JS files it shouldn't be checking anyway.
@NotYoojun
Copy link

NotYoojun commented Apr 2, 2025

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) {

@bolatovumar
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

8 participants