Skip to content

fix(build): externalize node:* in the Vite lib build so CLI bundles work - #159

Merged
JosunLP merged 1 commit into
devfrom
hotfix/vite-externalize-node-builtins
Jun 29, 2026
Merged

fix(build): externalize node:* in the Vite lib build so CLI bundles work#159
JosunLP merged 1 commit into
devfrom
hotfix/vite-externalize-node-builtins

Conversation

@JosunLP

@JosunLP JosunLP commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Problem

Vite's library build bundled node:* imports into its browser-external stub (an empty default export). That left await import('node:fs/promises') in the optional CLI entry resolving to undefined, so the published bquery-view-compile CLI crashed at runtime with e is not a function when run against the dist build.

Fix

Mark node:* as external in rollupOptions so those imports are emitted verbatim and resolved by Node at runtime:

rollupOptions: {
  external: (id) => id.startsWith('node:'),
  output: { ... },
}

Browser entries never import node:*, so this is a no-op for them.

Verification

  • Rebuilt dist; the vite-browser-external stub is gone from dist/view-compiler.es.mjs (0 references, was 1).
  • bquery-view-compile --out-dir … file.html runs end-to-end against the built bundle (1/1 compiled).

Note

This is the standalone hotfix for dev. The same one-line change is also present in the stable-graduation PR #157 (which introduces the bquery-i18n CLI that surfaced the bug); since the change is byte-identical, the branches reconcile cleanly when both land — or the line can be dropped from #157 once this merges.

🤖 Generated with Claude Code

Vite's library build bundled `node:*` imports into its browser-external stub
(an empty default export). That left `await import('node:fs/promises')` in the
optional CLI entry resolving to `undefined`, so the published
`bquery-view-compile` CLI crashed at runtime ("e is not a function").

Mark `node:*` as external in `rollupOptions` so those imports are emitted
verbatim and resolved by Node at runtime. Browser entries never import
`node:*`, so this is a no-op for them.

Verified: rebuilt `dist`, the browser-external stub is gone from
`dist/view-compiler.es.mjs` (0 references), and `bquery-view-compile` runs
end-to-end against the built bundle.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64b0eea8-89f3-4229-9a5e-8c3d4e1275ed

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/vite-externalize-node-builtins

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the build Changes to the build and meta files label Jun 29, 2026
@JosunLP
JosunLP merged commit 0002d55 into dev Jun 29, 2026
9 checks passed
@JosunLP
JosunLP deleted the hotfix/vite-externalize-node-builtins branch June 29, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Changes to the build and meta files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant