feat: add browser-only WASM build variant#622
Merged
lovasoa merged 1 commit intosql-js:masterfrom Feb 12, 2026
Merged
Conversation
…ings in bundlers
When bundling sql.js for browser environments, tools like Vite, Webpack,
and esbuild emit warnings about `require("node:fs")` and
`require("node:crypto")` being externalized for browser compatibility.
This adds a new `sql-wasm-browser.js` build variant compiled with
`-s ENVIRONMENT=web,worker`, which completely eliminates Node.js code
paths from the generated JavaScript. The browser variant is exposed via
the `exports` field in package.json using the `browser` condition, so
bundlers automatically select the clean version.
The original `sql-wasm.js` with full Node.js support is preserved as
the `default` export, ensuring no breaking changes for existing users.
Closes sql-js#620
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Verified with pnpm patchI've verified this change works in a real project (a Chrome extension built with WXT + Vite 7 + rolldown). After applying the patch:
For pnpm users who need this fix nowYou can use
|
Contributor
Author
|
Patch file: https://gist.github.com/rxliuli/06a26d53fa45359c8079834aa20d4369 Download the raw file and place it at |
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
When bundling sql.js for browser environments, tools like Vite, Webpack, and esbuild emit warnings about
require("node:fs")andrequire("node:crypto")being externalized for browser compatibility. Theserequire()calls exist in the emcc-generated code because the defaultENVIRONMENTincludesnode.This PR adds a new
sql-wasm-browser.jsbuild variant that eliminates these warnings:EMFLAGS_WASM_BROWSERin Makefile: same asEMFLAGS_WASMbut with-s ENVIRONMENT=web,worker, which tells Emscripten to strip all Node.js code paths at compile timedist/sql-wasm-browser.js(optimized) anddist/sql-wasm-browser-debug.js(debug)package.json: bundlers targeting browsers automatically resolve to the cleansql-wasm-browser.jsvia thebrowsercondition, while Node.js and other environments continue using the originalsql-wasm.jsBefore (bundler output)
After
No sql.js related warnings.
Build comparison
require()callssql-wasm.js(unchanged)require("node:fs"),require("node:crypto")sql-wasm-browser.js(new).wasmbinaryNo breaking changes — the original
sql-wasm.jsis fully preserved as thedefaultexport.Closes #620
Test plan
sql-wasm-browser.jswithmake dist/sql-wasm-browser.js— succeedssql-wasm-browser.jscontains zerorequire()callssql-wasm.jsstill contains Node.js support code🤖 Generated with Claude Code