Overview

This PR implements full npm package import support for both the tscircuit CLI and tscircuit.com website, addressing issue #760.

Key Features

  • CLI Support: Bundles npm dependencies locally using esbuild
  • Web Support: Automatically transforms imports to CDN URLs (no installation needed)
  • Multiple CDN Providers: Skypack, jsDelivr, unpkg, esm.sh
  • Import Map Generation: Native browser ES module support
  • Validation: Checks for missing packages and suggests installation

API

// Your circuit code - works in both CLI and web!
import lodash from "lodash"
import { Circuit, Resistor } from "@tscircuit/core"
const values = lodash.range(1, 5)
// ... use npm packages naturally
// Programmatic API
import { withNpmImports } from "tscircuit"
const result = await withNpmImports({
code: userCode,
environment: 'cli' | 'web' | 'auto',
cdnProvider: 'skypack' | 'jsdelivr' | 'unpkg' | 'esm'
})

Testing

# Run tests
bun test test/npm-imports.test.ts # ✅ 6 tests pass
# Try examples
bun run examples/npm-import-usage.ts
image

How It Works

  • CLI: Uses esbuild to bundle dependencies from node_modules
  • Web: Transforms import x from "package"import x from "https://cdn.skypack.dev/package"
  • Smart Detection: Preserves @tscircuit/* and relative imports
  • Auto Environment: Detects CLI vs browser automatically

Fixes #760 /claim #760

Claim

Total prize pool $150
Total paid $0
Status Pending
Submitted September 06, 2025
Last updated September 06, 2025

Contributors

RI

Rishi Mondal

@MAVRICK-1

100%

Sponsors

TS

tscircuit

@tscircuit

$150