fix(cli): emit station IDL factory as CommonJS#639
Merged
Conversation
The generated `cli/src/audit/generated/station.did.js` (produced by
`didc bind --target js`) uses ES module syntax (`export const idlFactory
= ...`), but the cli package is plain CommonJS. On Node ≤ 20.18 (the
version pinned via `.nvmrc`), `require('./generated/station.did.js')`
throws `SyntaxError: Unexpected token 'export'` at module-load time —
breaking every orbit-cli invocation, including `registry publish`,
`release publish`, and the new `audit` subcommand.
Transform the file to `exports.X = ...` form so any require()-loading
Node version accepts it. The transform is one sed substitution and is
wired into the `generate-station-types` script so future re-generations
don't reintroduce the breakage. Local Node 20.20+ silently auto-detects
ESM in .js files, which is why this didn't surface during development.
Follow-up to #638.
|
✅ No security or compliance issues detected. Reviewed everything up to e7c6f15. Security Overview
Detected Code Changes
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Node 20.18 runtime failure in orbit-cli caused by an ESM-generated Candid JS binding being loaded via require() in a CommonJS package, which prevented all CLI commands from starting.
Changes:
- Converted the generated Station Candid JS bindings (
station.did.js) fromexport const …toexports.…for CommonJS compatibility. - Updated the
generate-station-typesscript to apply the same transformation during regeneration to prevent regressions.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cli/src/audit/generated/station.did.js |
Switches top-level exports to CommonJS (exports.idlFactory, exports.init) so Node 20.18 can load the module. |
cli/package.json |
Ensures regenerated JS bindings are emitted as CommonJS via a sed transform in generate-station-types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aterga
approved these changes
Jun 24, 2026
aterga
added a commit
that referenced
this pull request
Jun 25, 2026
#639 (merged) emits the station IDL factory as CommonJS, so the built CLI no longer crashes with `Unexpected token 'export'`. Verified after merging main: `pnpm --filter orbit-cli build` produces a CLI that runs `audit` directly with no repair. Removes the now-dead repair step from run-audit.sh, drops the ESM gotcha and its troubleshooting entry from SKILL.md (four gotchas → three), and simplifies the "don't trust the global CLI" note accordingly. Co-Authored-By: Claude Opus 4.8 <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.
Summary
cli/src/audit/generated/station.did.js(vendored fromdidc bind --target js) uses ES module syntax. The cli package is plain CommonJS..nvmrcand the one CI uses —require()of that file throwsSyntaxError: Unexpected token 'export'at module-load time. Every orbit-cli invocation fails:registry publish,release publish,audit, even--help.disaster-recovery.spec.ts › can recover uninstalled stationfailing at `execSync(`orbit-cli registry publish --app station`)`).Motivation
Newer Node versions (≥ 20.20, backported from Node 22's `--experimental-detect-module`) silently auto-detect ESM in `.js` files, which masked the problem locally during development. CI's pinned Node 20.18 has no such fallback.
What changed
cli/src/audit/generated/station.did.js— transformed via a single sed substitution: `export const X = ...` → `exports.X = ...`. Two top-level exports affected: `idlFactory` and `init`.cli/package.json(`generate-station-types`) — same sed pipe added to the regen script so future re-generations from `spec.did` don't reintroduce the breakage.Test plan
Follow-up to #638.