Skip to content

RangeError - Maximum call stack size exceeded - in tsserver / vscode extension host - when providing type args to fn lambda #61110

Open
@holvi-sebastian

Description

@holvi-sebastian

🔎 Search Terms

RangeError
Maximum call stack size exceeded
stack overflow
vscode
intellisense
autocomplete
suggestions

🕗 Version & Regression Information

This is the behaviour in every version I tried, and I reviewed the FAQ for entries about 'generic function arguments'.

I have tried this in 5.5.4 up to next.

⏯ Playground Link

https://github.com/cleric-sh/repro/tree/tsserver-RangeError-in-vscode

💻 Code

Can't reproduce this in TS Playground, unfortunately, as it occurs with multiple files.

The error occurs when built (compiled) artefacts from one workspace package are imported by another, consuming package. In this case, consumer -> pkg.

To see this error, the repo really needs to be viewed in VSCode.

In consumer/index.ts:

import { Container } from "pkg";

/**
 * The error is also displayed if importing the .d.ts file directly.
 */
// import { Container } from "../pkg/dist/Container";

export class HomePage extends Container<unknown> {  
  // Invoke intellisense completion / suggestions here
  // Observe the error in Output > Extension Host

  // Go to * Go to 'pkg/dist/Container.ts' to trigger the error.
}

In pkg/dist/Container.d.ts:

import type { TraverseArgs } from './traverse';

export declare class Container<P> {
  /**
   * This line (including generic arg for 'TraverseArgs') produces 'Maximum call stack size exceeded' in Extension Host.
   * Go to 'consumer/index.ts' to trigger the error.
   */
  $traverse<T>(...args: [typeof TraverseArgs<T>]): unknown

  /**
   * The same line without the generic arg for 'TraverseArgs' does not emit the same error.
   */
  // $traverse<T>(...args: [typeof TraverseArgs]): unknown
}

In pkg/dist/traverse.d.ts:

export declare const TraverseArgs: <T>() => unknown

🙁 Actual behavior

Maximum call stack size exceeded error in tsserver

The code in this repository produces an error in tsserver in vscode's Extension Host.

The pkg workspace represents a locally built package in a workspace that is referenced by consumer.

Steps to repro
  1. pnpm i

  2. Open the Output > Extension Host view

  3. Go to consumer/index.ts

  4. Trigger autocomplete / suggestions intellisense action inside the HomePage class, as per comments.

  5. Observe the error in Output.

  6. Go to pkg/dist/Container.d.ts

  7. Comment out the traverse fn and uncomment the alternative.

  8. Go to consumer/index.ts and trigger suggestions again.

  9. Note that the suggestions are now working and the error is not emitted.

The blame

In this case, passing arguments to the lambda causes the error:

  $traverse<T>(...args: [typeof TraverseArgs<T>]): unknown
                              //This arg --> ^

Whereas the following does not:

  $traverse<T>(...args: [typeof TraverseArgs]): unknown
The error

The error produced is:

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at Object.toFileNameLowerCase [as getCanonicalFileName] (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:3364:46)
    at getCanonicalFileName (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:127619:17)
    at toPath (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:8901:10)
    at toPath3 (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:126111:12)
    at getResolvedProjectReferenceToRedirect (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:127453:78)
    at getRedirectReferenceForResolution (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:126074:22)
    at getCompilerOptionsForFile (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:127520:20)
    at Object.getDefaultResolutionModeForFile2 [as getDefaultResolutionModeForFile] (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:128547:62)
    at resolveExternalModule (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:53540:151)
    at resolveExternalModuleNameWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:53517:61)
    at resolveExternalModuleName (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:53514:12)
    at getAlternativeContainingModules (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:53999:32)
    at getWithAlternativeContainers (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54064:58)
    at getContainersOfSymbol (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54031:14)
    at getSymbolChain (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:56557:27)
    at lookupSymbolChainWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:56542:36)
    at lookupSymbolChain (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:56536:14)
    at symbolToTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:56710:21)
    at serializeTypeName (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57259:14)
    at Object.serializeTypeName (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54836:16)
    at tryVisitTypeQuery (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136241:39)
    at visitExistingNodeTreeSymbolsWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136439:24)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136189:22)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
    at typeToTypeNodeWorker (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55291:16)
    at typeToTypeNodeHelper (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55072:24)
    at serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:57306:14)
    at Object.serializeExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:54794:16)
    at visitExistingNodeTreeSymbols (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136194:27)
    at visitNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:93631:19)
    at tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136179:25)
    at Object.tryReuseExistingTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:136171:14)
    at createAnonymousTypeNode (<redacted>/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:55469:53)
	at n.create (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:486366)
	at y.dispatchResponse (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:480336)
	at y.dispatchMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:479134)
	at ChildProcess.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:478627)
	at ChildProcess.emit (node:events:518:28)
	at emit (node:internal/child_process:950:14)
	at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
2025-02-04 14:21:53.264 [error] [vscode.typescript-language-features] provider FAILED

🙂 Expected behavior

Suggestions to appear as expected, no error to be emitted.

Additional information about the issue

This issue does not occur if pkg exports the ts files directly, instead of built .d.ts artefacts.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions