Skip to content

TS Server fatal error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isUnaryExpression'. #53637

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

Closed
ghost opened this issue Mar 31, 2023 · 12 comments · Fixed by #53666
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@ghost
Copy link

ghost commented Mar 31, 2023

Type: Bug

❗️❗️❗️ Please fill in the sections below to help us diagnose the issue ❗️❗️❗️

TypeScript Version: 5.0.2

Steps to reproduce crash

TS Server Log

❗️ Server logging disabled. To help us fix crashes like this, please enable logging by setting:

"typescript.tsserver.log": "verbose"

After enabling this setting, future crash reports will include the server log.

TS Server Error Stack

Server: semantic

Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isUnaryExpression'.
    at cast (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:3443:16)
    at Object.parenthesizeOperandOfPrefixUnary (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:21786:50)
    at Object.createPrefixUnaryExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:23915:41)
    at parsePrefixUnaryExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33520:32)
    at parseSimpleUnaryExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33572:16)
    at parseUnaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33554:35)
    at parseBinaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33472:25)
    at parseAssignmentExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33145:18)
    at parseArgumentOrArrayLiteralElement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34228:170)
    at parseListElement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31579:12)
    at parseDelimitedList (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31818:24)
    at parseArrayLiteralExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34241:22)
    at parsePrimaryExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34178:16)
    at parseMemberExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33655:24)
    at parseLeftHandSideExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33649:82)
    at parseUpdateExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33624:24)
    at parseUnaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33550:32)
    at parseBinaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33472:25)
    at parseAssignmentExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33145:18)
    at parseArgumentOrArrayLiteralElement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34228:170)
    at parseListElement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31579:12)
    at parseDelimitedList (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31818:24)
    at parseArrayLiteralExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34241:22)
    at parsePrimaryExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34178:16)
    at parseMemberExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33655:24)
    at parseLeftHandSideExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33649:82)
    at parseUpdateExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33624:24)
    at parseUnaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33550:32)
    at parseBinaryExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33472:25)
    at parseAssignmentExpressionOrHigher (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33145:18)
    at parseExpression (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:33111:16)
    at doOutsideOfContext (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:30808:12)
    at allowInAnd (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:30829:12)
    at parseExpressionOrLabeledStatement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34623:24)
    at parseStatement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:34855:12)
    at parseListElement (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31579:12)
    at parseList (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:31564:19)
    at parseSourceFileWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:30624:24)
    at Object.parseSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:30457:20)
    at createSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:30290:21)
    at createLanguageServiceSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135139:22)
    at acquireOrUpdateDocument (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:132053:26)
    at Object.acquireDocumentWithKey (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:131978:12)
    at getOrCreateSourceFileByPath (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135464:31)
    at Object.getOrCreateSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135444:14)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135376:42
    at Object.getSourceFileWithCache [as getSourceFile] (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117127:24)
    at findSourceFileWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119460:23)
    at findSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119380:20)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119329:22
    at getSourceFileFromReferenceWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119298:26)
    at processSourceFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119327:5)
    at processRootFile (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119123:5)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117908:41
    at forEach (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:2307:22)
    at createProgram (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117908:5)
    at synchronizeHostData (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135400:15)
    at Object.getProgram (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:135472:5)
    at ConfiguredProject2.updateGraphWorker (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172153:41)
    at ConfiguredProject2.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:172090:32)
    at ConfiguredProject2.updateGraph (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:173272:24)
    at _ProjectService.createLoadAndUpdateConfiguredProject (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:174879:13)
    at _ProjectService.assignProjectToOpenedScriptInfo (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:175970:26)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:176250:64
    at flatMap (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:2555:17)
    at _ProjectService.applyChangesInOpenFiles (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:176250:24)
    at updateOpen (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:177395:29)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:179962:69
    at IpcIOSession.executeWithRequestId (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:179954:14)
    at IpcIOSession.executeCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:179962:29)
    at IpcIOSession.onMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:180004:51)
    at process.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:181571:14)
    at process.emit (node:events:526:28)
    at emit (node:internal/child_process:938:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

VS Code version: Code 1.77.0 (Universal) (7f329fe6c66b0f86ae1574c2911b681ad5a45d63, 2023-03-29T09:57:11.797Z)
OS version: Darwin arm64 22.4.0
Modes:
Sandboxed: Yes

System Info
Item Value
CPUs Apple M1 Max (10 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 27, 19, 14
Memory (System) 32.00GB (3.18GB free)
Process Argv --crash-reporter-id 2e515fa3-9ac9-427f-b4e8-572c4c6c77ee
Screen Reader no
VM 0%
Extensions (23)
Extension Author (truncated) Version
vscode-expo byC 0.9.2
path-intellisense chr 2.8.4
gitignore cod 0.9.0
vscode-eslint dba 2.4.0
xml Dot 2.5.1
gitlens eam 13.4.0
auto-close-tag for 0.5.14
auto-rename-tag for 0.1.10
codespaces Git 1.14.2
remotehub Git 0.54.0
vscode-pull-request-github Git 0.62.0
dotenv mik 1.0.1
vscode-docker ms- 1.24.0
remote-repositories ms- 0.32.0
vscode-react-native msj 1.10.2
color-highlight nau 2.5.0
indent-rainbow ode 8.3.1
material-icon-theme PKi 4.25.0
vscode-xml red 0.24.0
vscode-yaml red 1.12.2
code-spell-checker str 2.20.3
code-spell-checker-portuguese-brazilian str 2.0.12
markdown-all-in-one yzh 3.5.1

(1 theme extensions excluded)

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30610678
nodejswelcome1cf:30587006
3biah626:30602489
pyind779:30671433
f6dab269:30613381
pythonsymbol12:30671437
a9j8j154:30646983
showlangstatbar:30672706
vsctsb:30677850
vscodeenable:30660116
pythonb192:30669360
defaultazurewalk:30687958
pythonms35:30701012

@nathanlepori
Copy link

For me this was because of the React Native's new Hermes Engine. It produces binary .js files which tsc tries and fails to compile (because they aren't actually js). The solution is to exclude the dist folder by adding the following to your tsconfig.json:
"exclude": [..., "dist"]

For example if using "extends": "expo/tsconfig.base" you can copy the original array and add the dist folder:
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js", "dist"]

@ghost
Copy link
Author

ghost commented Apr 3, 2023

For me this was because of the React Native's new Hermes Engine. It produces binary .js files which tsc tries and fails to compile (because they aren't actually js). The solution is to exclude the dist folder by adding the following to your tsconfig.json: "exclude": [..., "dist"]

For example if using "extends": "expo/tsconfig.base" you can copy the original array and add the dist folder: "exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js", "dist"]

Worked for me too! thanks

@jakebailey
Copy link
Member

Can anyone provide the file which causes TS to crash? The stack trace is long enough that I don't think we can come up with a test case out of thin air.

@jakebailey
Copy link
Member

Metapoint: it's really not great that Hermes is writing .js files that don't contain JS code. All that's likely to do is cause tools to crash or waste time, though in this particular case, these files should really be excluded because they're output files and so peoples' tsconfigs are definitely misconfigured.

@RyanCavanaugh
Copy link
Member

We could really use a Hermes binary JS file for each Hermes bytecode version so we can detect and avoid them. Anyone able to upload those artifacts?

@nathanlepori
Copy link

Metapoint: it's really not great that Hermes is writing .js files that don't contain JS code. All that's likely to do is cause tools to crash or waste time, though in this particular case, these files should really be excluded because they're output files and so peoples' tsconfigs are definitely misconfigured.

That's a good point, according to this draft RFC the files are supposed to have the .hbc file extension. No idea why React Native emits them as .js.

We could really use a Hermes binary JS file for each Hermes bytecode version so we can detect and avoid them. Anyone able to upload those artifacts?

Unfortunately I cannot provide the binary because it's part of an internal project, however any project compiled with the latest React Native/Expo version should produce the bytecode you're looking for. Also from the above draft RFC it seems like Hermes bytecode should always start with the magic number 0xC61FBC03C103191F. I have been able to confirm that using my own bytecode. That could be used for detection as an alternative to the extension.

@nathanlepori
Copy link

Or as an alternative idea tsc could ignore any file with unrecognized characters and issue a warning instead of erroring out, but that might be a bit too drastic of a change.

@cortinico
Copy link

That's a good point, according to this draft RFC the files are supposed to have the .hbc file extension. No idea why React Native emits them as .js.

Hi all,
Nicola here from the React Native team.

Providing context from the React Native Android + Hermes build pipeline. To the best of my knowledge, we don't emit .js files from Hermes.

Hermes produces .hbc files, which gets renamed to the bundle filename that the user specifies, that usually ends with .bundle.
For example for our RN Tester project (the sample app of React Native), the hermes output will be placed inside a file located in:

packages/rn-tester/android/app/build/generated/assets/createBundleHermesReleaseJsAndAssets/RNTesterApp.android.bundle

Users can override the final bundle location, so if they specify a filename that ends with .js, we will honor it.

So I believe here the root cause could be some sort of misconfiguration on the user side.

Codepointers to the Android logic for futher context: https://github.com/facebook/react-native/blob/bece6500f7d6374eab09917c9afd3bf6142f0b61/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt#L92-L113

@RyanCavanaugh
Copy link
Member

Please, someone, please

please post a concrete repro (zip file, repo, etc)

We really do need one! Please!

@jakebailey
Copy link
Member

jakebailey commented Apr 4, 2023

Related is #50675; is everyone here using expo? Is that who's writing to the wrong file extension?

But again, please... a repro...

@ghost
Copy link

ghost commented Apr 4, 2023

Related is #50675; is everyone here using expo? Is that who's writing to the wrong file extension?

But again, please... a repro...

eas is what's writing the files which are causing the issue, see below.

#53114 (comment)

npx create-react-app test-app --template expo-template-tabs
cd test-app
eas update --auto
ls -al ./dist

@ide
Copy link

ide commented Apr 12, 2023

It sounds like there are two issues at hand, namely that build artifacts are being analyzed by the language server and that Hermes bytecode files with the .js file extension are being parsed as JavaScript. To help with the second issue, the next major release of Expo CLI will export Hermes bytecode files using the .hbc file extension (see expo/expo#21990).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants