fix(cli): resolve bunx execution -S not found error on Windows#24653
fix(cli): resolve bunx execution -S not found error on Windows#24653ilkerozgedik wants to merge 0 commit intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a compatibility issue where the use of the -S flag in shebang lines caused execution errors on Windows systems when using tools like bunx. By shifting the suppression of deprecation warnings from the shebang to a runtime programmatic check, the project ensures a more robust and cross-platform execution experience for developers. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request replaces shebang-based warning suppression with a manual override of process.emitWarning in packages/a2a-server/src/http/server.ts and packages/cli/index.ts to ensure compatibility across platforms like Windows. The review feedback correctly identifies that due to ESM hoisting, static imports are evaluated before the suppression logic, which may allow deprecation warnings to leak during the initial module load. The reviewer suggests using dynamic imports or a dedicated initialization module to ensure the override is active before any dependencies are processed.
| // Suppress DEP0040 (Punycode deprecation warning) safely, as Windows limits shebang flags. | ||
| const originalEmitWarning = process.emitWarning; | ||
| process.emitWarning = ((...args: unknown[]) => { | ||
| const [warning, type, code] = args; | ||
| if (type === 'DEP0040' || code === 'DEP0040' || (type === 'DeprecationWarning' && String(warning).includes('punycode'))) { | ||
| return; | ||
| } | ||
| return Reflect.apply(originalEmitWarning, process, args); | ||
| }) as typeof process.emitWarning; | ||
|
|
||
| import * as url from 'node:url'; | ||
| import * as path from 'node:path'; |
There was a problem hiding this comment.
In ECMAScript Modules (ESM), static import statements are hoisted and evaluated before the module body runs. This means the process.emitWarning override will execute only after all static imports (including those on lines 22-23 and their transitive dependencies) have been fully evaluated. If any of these modules trigger the punycode deprecation warning during their evaluation, the suppression will be ineffective.
To correctly suppress warnings during module loading in ESM, you should either:
- Move the suppression logic to a separate file and import it as the very first import in this file.
- Use dynamic
import()for all dependencies after the override logic.
References
- When a new file is intended to replace a file that will be deprecated, it is acceptable to duplicate definitions from the old file to avoid creating a dependency on the code that is being phased out.
packages/cli/index.ts
Outdated
| // Suppress DEP0040 (Punycode deprecation warning) safely, as Windows limits shebang flags. | ||
| const originalEmitWarning = process.emitWarning; | ||
| process.emitWarning = ((...args: unknown[]) => { | ||
| const [warning, type, code] = args; | ||
| if (type === 'DEP0040' || code === 'DEP0040' || (type === 'DeprecationWarning' && String(warning).includes('punycode'))) { | ||
| return; | ||
| } | ||
| return Reflect.apply(originalEmitWarning, process, args); | ||
| }) as typeof process.emitWarning; | ||
|
|
||
| import { main } from './src/gemini.js'; | ||
| import { FatalError, writeToStderr } from '@google/gemini-cli-core'; | ||
| import { runExitCleanup } from './src/utils/cleanup.js'; |
There was a problem hiding this comment.
In ESM, static import statements are hoisted and evaluated before the module body. Consequently, the process.emitWarning override will run after the modules on lines 19-21 have been loaded, making the suppression ineffective if they trigger the warning during evaluation. Using dynamic import() ensures the override is active before the modules are loaded.
// Suppress DEP0040 (Punycode deprecation warning) safely, as Windows limits shebang flags.
const originalEmitWarning = process.emitWarning;
process.emitWarning = ((...args: unknown[]) => {
const [warning, type, code] = args;
if (type === 'DEP0040' || code === 'DEP0040' || (type === 'DeprecationWarning' && String(warning).includes('punycode'))) {
return;
}
return Reflect.apply(originalEmitWarning, process, args);
}) as typeof process.emitWarning;
const { main } = await import('./src/gemini.js');
const { FatalError, writeToStderr } = await import('@google/gemini-cli-core');
const { runExitCleanup } = await import('./src/utils/cleanup.js');c7f8351 to
4ad792c
Compare
Summary
Fixed execution failure on Windows when running
bunx @google/gemini-cli. The shebang#!/usr/bin/env -S node --no-warnings=DEP0040uses the-Sflag which is a GNUenvextension not supported on Windows, causing:Details
#!/usr/bin/env nodein both entry points (packages/cli/index.ts,packages/a2a-server/src/http/server.ts)DEP0040(punycode deprecation) suppression to a dedicatedsuppress-warnings.tsmodule that is imported first — this correctly handles ESM module hoisting, ensuring the override runs before any other module is evaluatedRelated Issues
Closes #24654
How to Validate
On a Windows machine:
bunx @google/gemini-cli— should launch without any errorerror: interpreter executable "-S" not found in %PATH%Pre-Merge Checklist