fix: add navigator shim for Node.js 22+ compatibility in code-server #10400
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.
Related GitHub Issue
Closes: #10391
Description
This PR attempts to address Issue #10391 by adding a navigator shim in the esbuild configuration to fix the
PendingMigrationErrorthat occurs on code-server with Node.js 22+.The Problem:
In Node.js 22+,
navigatoris now a global object. Several bundled dependencies (debug, axios, pdf-parse) checktypeof navigator !== "undefined"and then try to access properties likenavigator.userAgent. VS Code's extension host intercepts these accesses and throwsPendingMigrationErrorto help extensions migrate.The Solution:
Added a JavaScript banner in the esbuild configuration that creates a safe navigator stub before any bundled code runs. The stub provides empty/default values for commonly accessed navigator properties:
userAgent,platform,appName,appVersion,product: empty stringsuserLanguage: undefinedlanguages: empty arrayhardwareConcurrency: 1standalone: falseonLine: trueThis shim is applied to both the extension and worker bundles via the shared
buildOptionsconfiguration.Test Procedure
node --check src/esbuild.mjsPre-Submission Checklist
Documentation Updates
Additional Notes
navigator.onLineaccess (Issue [Bug] Nightly build crashes with "PendingMigrationError: navigator is now a global in nodejs" #6356)_navigatorShimAppliedflag to prevent double application