Skip to content

Make SQLite runtime loading safe for Node-targeted bundles#2

Draft
Copilot wants to merge 3 commits intodevfrom
copilot/fix-node-targeted-npm-clis
Draft

Make SQLite runtime loading safe for Node-targeted bundles#2
Copilot wants to merge 3 commits intodevfrom
copilot/fix-node-targeted-npm-clis

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 17, 2026

Node-targeted CLIs consuming @wgtechlabs/config-engine could still fail at runtime because bundled output retained a bun:sqlite import. This change keeps Bun as the primary runtime while making the package safe to load from Node-targeted artifacts.

  • Runtime adapter loading

    • Replace the static Bun SQLite import path with runtime-only resolution.
    • Keep Node on better-sqlite3 via the existing adapter path.
    • Preserve the Bun-first behavior without leaking bun:* imports into Node bundles.
  • Bundling regression coverage

    • Add a focused runtime test that bundles a small entrypoint for target: "node".
    • Assert the emitted bundle does not contain a static bun:sqlite import and can be loaded by Node.
  • Documentation

    • Clarify that the Bun SQLite backend is loaded only at runtime on Bun, so Node-targeted bundles can consume the package safely.
import { createRequire } from "node:module";

const runtimeRequire = createRequire(import.meta.url);

function openBunDatabase(filepath: string) {
	const { Database } = runtimeRequire(getBunSqliteSpecifier());
	return new Database(filepath);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Node-targeted npm CLIs fail because the package imports bun:sqlite</issue_title>
<issue_description>## Summary
Using @wgtechlabs/config-engine in a package that is built for Node and published to npm can fail at runtime because the package imports bun:sqlite.

In practice this makes the package Bun-only for bundled Node CLI releases, even when the consumer application itself targets Node.

Repro

Consumer build:

bun build src/index.ts --outfile dist/index.js --target node
node dist/index.js --version

Actual result

Node fails during module loading with:

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'bun:'

Why this matters

I hit this in a released npm CLI because Bun bundled the dependency graph into a Node-targeted artifact, and the resulting build still contained bun:sqlite imports.

That means the package is not currently safe to consume from a published Node CLI unless the consumer is also effectively Bun-only.

Expected result

One of these should happen:

  1. The package provides a Node-safe backend or conditional runtime adapter.
  2. The package clearly documents that it is Bun-only.
  3. The package exposes a storage abstraction that allows Node consumers to avoid bundling bun:* imports.

Notes

I am happy to help test a fix from the consumer side.
</issue_description>

<agent_instructions>Let's add support to both node and bun, but primarily we support bun.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 2 commits March 17, 2026 14:18
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Node-targeted npm CLIs failing due to bun:sqlite import Make SQLite runtime loading safe for Node-targeted bundles Mar 17, 2026
Copilot AI requested a review from warengonzaga March 17, 2026 14:21
@warengonzaga warengonzaga changed the base branch from main to dev March 17, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node-targeted npm CLIs fail because the package imports bun:sqlite

2 participants