fix: use DI for vscode API in nodeLauncher instead of direct import#2369
Merged
connor4312 merged 2 commits intoJun 3, 2026
Merged
Conversation
Member
|
THanks for identifying the issue and the PR. We should actually switch the Otherwise the code will still error when executed. |
908d885 to
031a60a
Compare
nodeLauncher.ts was directly importing 'vscode', which causes both a build error (esbuild can't resolve it) and a runtime error (module doesn't exist outside VS Code) for standalone server bundles like vsDebugServerBundle. Switch to the established pattern used elsewhere in the codebase (e.g. defaultBrowserProvider.ts, nodeBinaryProvider.ts): - Use 'import type' so no require() is emitted at runtime - Inject the vscode API via @optional() @Inject(VSCodeApi) - Guard usage with an undefined check for non-VS Code contexts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Thanks Connor - I've adjusted the PR. Let me know if it doesn't align with your comments :) |
connor4312
reviewed
Jun 3, 2026
Co-authored-by: Connor Peet <connor@peet.io>
joj
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
vsDebugServerBundle(and other non-extension bundles whereisInVsCode=false) fails to build with:\
X [ERROR] Could not resolve "vscode"
\\
This started after aeb21f0 ("Provide an opt-out for debug entrypoint resolution") added
import * as vscode from 'vscode'tonodeLauncher.ts.Root Cause
The direct
import * as vscode from 'vscode'causes two problems for standalone (non-VS Code) bundles:vscodemodule since it's only in theexternallist whenisInVsCodeis truerequire('vscode')would fail at runtime since the module doesn't exist outside VS CodeFix
Follows the established pattern used in
defaultBrowserProvider.ts,nodeBinaryProvider.ts, and other files:import type * as vscodeType from 'vscode'– type-only import, erased at runtime@optional() @inject(VSCodeApi) private readonly vscode?: typeof vscodeType– DI injection,undefinedoutside VS CodereadConfigcall with anif (!this.vscode)check, falling back to the original behavior (no entrypoint resolution)