fix: resolve use-m ESM/CJS interop for yargs on Node.js v23+ - #56
Open
fredericgermain wants to merge 2 commits into
Open
fix: resolve use-m ESM/CJS interop for yargs on Node.js v23+#56fredericgermain wants to merge 2 commits into
fredericgermain wants to merge 2 commits into
Conversation
Extends the Node.js v23+ compatibility fix from the initial commit to cover all four use-m loaded packages, not just yargs: - archiver: same .default unwrap pattern as yargs (it's a callable default export) - yargsHelpers: rename to _yargsHelpers for consistency - command-stream: rename to _commandStream; $ is a named export at top level, so no .default unwrap needed (verified empirically) Also adds archiverFn as the resolved callable, replacing direct archiver() calls in saveProfileSilent and saveProfile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Problem
Closes #55
claude-profilesfails on Node.js v23+ (and v24) with errors like:```
TypeError: hideBin is not a function
TypeError: yargs is not a function
TypeError: archiver is not a function
```
Root Cause
use-mdynamically loads CJS packages into an ESM context. On newer Node.js versions, it wraps default exports under a.defaultproperty instead of returning them directly. This affects callable default exports (yargs,archiver) and named exports accessed via helpers (yargs/helpers).Fix
Apply defensive
.defaultunwrapping to all fouruse-mloaded packages:```diff
-const [{ $ }, _yargs, yargsHelpers, archiver] = await Promise.all([
+const [_commandStream, _yargs, _yargsHelpers, _archiver] = await Promise.all([
use('command-stream@0.7.0'),
use('yargs@17.7.2'),
use('yargs@17.7.2/helpers'),
use('archiver@7.0.1')
]);
-// use-m wraps CJS modules under .default in ESM context; unwrap defensively
+// use-m wraps CJS modules under .default in ESM context on Node.js v23+; unwrap defensively
+// command-stream exports $ as a named export at the top level (not under .default)
+const { $ } = _commandStream;
const yargs = (typeof _yargs === 'function') ? _yargs : (_yargs?.default ?? _yargs);
-const hideBin = yargsHelpers?.hideBin ?? yargsHelpers?.default?.hideBin ?? ((argv) => argv.slice(2));
+const hideBin = _yargsHelpers?.hideBin ?? _yargsHelpers?.default?.hideBin ?? ((argv) => argv.slice(2));
+const archiverFn = (typeof _archiver === 'function') ? _archiver : (_archiver?.default ?? _archiver);
```
command-streamconst { $ } = _commandStream$is a named export at top level — no.defaultneededyargstypeof fn ? fn : fn.default ?? fn.defaultyargs/helpersx.hideBin ?? x.default.hideBin ?? fallbackhideBinis under.defaultarchivertypeof fn ? fn : fn.default ?? fn.defaultTesting
Verified on Node.js v24.12.0 —
claude-profiles --store globalandclaude-profiles --helpwork correctly after the fix.