fix: load ngspice engine without blob: import (fixes schematic simulation) - #1691
Open
rushabhcodes wants to merge 1 commit into
Open
fix: load ngspice engine without blob: import (fixes schematic simulation)#1691rushabhcodes wants to merge 1 commit into
rushabhcodes wants to merge 1 commit into
Conversation
…tion)
@tscircuit/ngspice-spice-engine@0.0.18 loads its WASM engine via
URL.createObjectURL + import("blob:..."), which the Node ESM loader
rejects ("Only URLs with a scheme in: file, data, and node are
supported... Received protocol 'blob:'"), breaking schematic simulation
on the server.
- Patch the package in postinstall to import the bundled
@tscircuit/eecircuit-engine directly, which also avoids a runtime CDN
fetch (matching the goal of #1686).
- Promote @tscircuit/eecircuit-engine to a runtime dependency since a
runtime dependency now imports it.
- Add a Node-level regression test: bun accepts blob: imports, so the
existing bun tests cannot catch this; the test spawns a real Node
process to simulate.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
rushabhcodes
force-pushed
the
fix/ngspice-blob-import-node
branch
from
June 27, 2026 21:28
e41e01f to
0bf3433
Compare
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.
Important
This PR is a proof / stopgap, not the real fix. It patches a dependency's
built output in
node_modulesso schematic simulation works on the servertoday. The actual defect lives in
@tscircuit/ngspice-spice-engineProblem
Schematic simulation fails on the server with:
Root cause:
@tscircuit/ngspice-spice-engine@0.0.18loads its WASM engine via an unconditionalURL.createObjectURL+import("blob:..."):Node's ESM loader only accepts
file:,data:, andnode:schemes, so this throws the moment ngspice loads. It is the missing piece of #1686:preloadNgspice()hits this same import and silently fails, so the error only surfaces at simulate time.What this PR does (the workaround)
scripts/apply-dependency-patches.mjs, mirroring the existingocct-import-jspatch with idempotency + "upstream changed" guards) to import the bundled@tscircuit/eecircuit-enginedirectly instead of fetching + blob-importing. This removes the blob import and the runtime CDN fetch (matching Prevent CDN fallback in production by preloading bundled ngspice #1686's goal).@tscircuit/eecircuit-engineto a runtimedependency(pinned to1.7.4, the same version the package's hardcoded CDN URL referenced) since a runtime dependency now imports it.tests/ngspice-node-loader.test.ts). The existing bun tests can't catch this — bun acceptsblob:imports — so the test spawns a real Node process to runsimulate().The real fix
The proper fix belongs in
@tscircuit/ngspice-spice-engine(lib/import-eecircuit-engine.ts). Today it loads the engine the same way in every environment:blob:URLs only resolve in browsers/bun; the Node ESM loader rejects them — so the package is broken for any Node consumer, not just this repo. It should be environment-aware. Either:data:URL (which the Node loader accepts) instead of a blob URL. This is the minimal change and matches the pattern@tscircuit/evalalready uses:@tscircuit/eecircuit-engineas a real dependency andreturn import("@tscircuit/eecircuit-engine"), optionally falling back to the CDN. This avoids the network round-trip entirely and is exactly what this PR forces via the patch.Once a fixed
@tscircuit/ngspice-spice-engineis published, the follow-up here is trivial: bump the dependency and removepatchNgspiceSpiceEngine()fromscripts/apply-dependency-patches.mjs.Verification
schematic-simulation-svgtest still passes