TypeScript: "Cannot read property 'lastIndexOf' of undefined" error in tsserver.js
Bug Report
π Search Terms
- lastIndexOf
π Version & Regression Information
- This is a crash in tsserver.js
- This happens in 4.2.2, 4.2.3 and next (4.3.0-dev.20210305), but not version 4.1.5
- node version v14.15.4
- windows version 20H2
π» Steps to reproduce
This happens consistently for me in the OmniSharp/omnisharp-vscode repository, when opening a typescript file with 4.2 installed.
- git clone https://github.com/OmniSharp/omnisharp-vscode.git
- cd omnisharp-vscode
- npm install
- npm install -g typescript@4.2.2
- code .
- Configure vscode to use the global ts server (for me this is
"typescript.tsdk": "C:\\Users\\phil\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib",) - Restart code
- Open the TypeScript output to view errors
π Actual behavior
The TypeScript language server crashes. Attached is a sample log: tsserver.zip
π Expected behavior
It to not crash.
Related Issues
Thereβs a couple of related issues in vscode repo such as microsoft/vscode#115905
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 28 (22 by maintainers)
@amcasey I am experiencing this issue on 4.4.3, MacOS 11.5. From logging, seems to be caused by this bit of our tsconfig:
"typeRoots": ["./typings", "./node_modules/@types"]which I understand should be legit?
This causes
guessDirectorySymlinkto be called with/[CWD]/typings/index.d.ts,/[CWD]/node_modules/@types/../../typings/index.d.tsleading to the same paths to be compared (/[CWD]/typings/index.d.ts) in thewhileloop untilCannot read property 'lastIndexOf' of undefinedUpdate:
git bisectsuggests the issue was introduced in4.4.0-dev.20210717Just a quick update on scheduling: last week we agreed to push this to 4.3 since telemetry shows that a limited number of machines are hitting this.
If you are impacted by this bug, once this issue is closed you should be able to install JavaScript and TypeScript nightly extension to pick up a fix instead of waiting on VS Code to pick up TS 4.3
Looks like 175K telemetry hits in the last day. (!!)
Edit: but theyβre from only 246 distinct machines.
Confirmed that converting:
Which effectively undoes #41292 but does fix my repro, now to try figure out what triggers the difference in behavior
@orta @RyanCavanaugh Weβve seen a few reports of they on the VS Code side. Is this something that we could look into for a TS 4.2 recovery build if the fix isnβt too risky?