Fix instruction generation error: Dynamic require of "util" is not supported#52
Merged
digitarald merged 3 commits intomicrosoft:mainfrom Mar 15, 2026
Merged
Conversation
…p.config.ts Co-authored-by: nicolehaugen <10600161+nicolehaugen@users.noreply.github.com>
Co-authored-by: nicolehaugen <10600161+nicolehaugen@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a runtime error (Dynamic require of "util" is not supported) when CJS dependencies like vscode-jsonrpc are bundled into the ESM output. The bundled CJS code calls require() which doesn't exist in ESM context.
Changes:
- Adds a
createRequireshim in the tsup banner to provide a realrequirefunction for bundled CJS dependencies - Preserves the shebang line for CLI executability
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 15, 2026
- Add [Unreleased] section documenting features from PRs #55, #60, #53, #52: - instructions --dry-run flag - VS Code batch instructions and multi-root workspace support - Enhanced .NET/F# detection with framework parsing - Windows .bat/.cmd spawn EINVAL fix - ESM/CJS createRequire banner fix - Model default updated to claude-sonnet-4.6 - TUI key binding changes (R for readiness, N for nested area) - Terminology de-branding - Fix stale claude-sonnet-4.5 reference in [2.0.0] section Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Repro:
1.) Run: agentrc instructions
2.) Error:
Generating instructions...
[agentrc:copilot] trying override AGENTRC_COPILOT_CLI_PATH=C:\Users\nicolela\AppData\Roaming\Code\User\globalStorage\github.copilot-chat\copilotCli\copilot.bat
[agentrc:copilot] override CLI is compatible
[agentrc:copilot] validating CLI compatibility with C:\Users\nicolela\AppData\Roaming\Code\User\globalStorage\github.copilot-chat\copilotCli\copilot.bat
Error: Failed to generate instructions with Copilot SDK. Ensure the Copilot CLI is installed (copilot --version) and logged in. Dynamic require of "util" is not supported
Fix: Add
createRequirebanner to tsup.config.tsProblem
When CJS dependencies (e.g.
vscode-jsonrpc) are bundled into an ESM output, calls torequire()inside those dependencies fail at runtime withReferenceError: require is not defined. ESM does not provide a globalrequire— it only exists in CommonJS.Solution
Add a
banner.jsentry in the tsup config that injects a shim at the top of the output bundle. This shim uses Node's built-inmodulepackage to create a realrequirefunction.Why this works
import { createRequire } from "module"— imports the factory from Node's built-inmodulepackage.createRequire(import.meta.url)— creates a CJS-compatiblerequire()function anchored to the bundle's file path.require("util"),require("path"), etc. now resolves normally.#!/usr/bin/env nodeshebang is included so the bundle is directly executable as a CLI.This pull request updates the Copilot SDK client creation logic to improve compatibility with Windows and better handle cases where the CLI cannot be executed directly. The main changes clarify when to bypass the SDK-managed process and use the external server mode, specifically for
.bat/.cmdshims and npx wrappers.Checklist