You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/runanywhere-web/packages/core/README.md
+85-34Lines changed: 85 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,25 +100,36 @@ On-device AI for the browser. Run LLMs, Speech-to-Text, Text-to-Speech, Vision,
100
100
101
101
## Package Structure
102
102
103
-
The Web SDK is a single npm package. Unlike native SDKs (iOS, Android, React Native, Flutter) which use separate packages per backend, the Web SDK compiles all inference backends into a single WebAssembly binary. Backend selection happens at WASM build time, not at the package level.
103
+
The Web SDK is split into three npm packages so you only ship the backends you need:
104
104
105
-
```
106
-
@runanywhere/web -- TypeScript API + pre-built WASM (all backends)
107
-
```
105
+
| Package | Description | Includes |
106
+
|---------|-------------|----------|
107
+
|[`@runanywhere/web`](https://www.npmjs.com/package/@runanywhere/web)| Core SDK — lifecycle, logging, events, model management, storage | TypeScript only (no WASM) |
The pre-built WASM includes llama.cpp (LLM/VLM), whisper.cpp (STT), and sherpa-onnx (TTS/VAD). Developers who need a smaller WASM binary with specific backends can [build from source](#building-from-source) with selective flags.
111
+
Install only what you need — `@runanywhere/web` is always required as the core.
The package includes pre-built WASM files in `node_modules/@runanywhere/web/wasm/`. Configure your bundler to serve these as static assets.
130
+
WASM files are included in `@runanywhere/web-llamacpp` and `@runanywhere/web-onnx`. Configure your bundler to serve them as static assets.
131
+
132
+
> **Important:** Your server **must** set Cross-Origin Isolation headers for `SharedArrayBuffer` and multi-threaded WASM to work. Without these headers the SDK falls back to single-threaded mode, which is significantly slower. See [Cross-Origin Isolation Headers](#cross-origin-isolation-headers) for all platforms (Nginx, Vercel, Netlify, Cloudflare, AWS, Apache).
> **Warning (Vite users):** You **must** add `@runanywhere/web-llamacpp` and `@runanywhere/web-onnx` to `optimizeDeps.exclude`. Vite's dependency pre-bundling flattens packages into `.vite/deps/`, which breaks the relative `import.meta.url` paths the SDK uses to locate its WASM files. Without this exclusion, WASM loading will fail with a "Failed to fetch dynamically imported module" error. This is a known Vite limitation with npm packages that resolve static assets via `import.meta.url`.
154
+
138
155
**Webpack:**
139
156
140
157
```javascript
@@ -145,9 +162,17 @@ module.exports = {
145
162
{ test:/\.wasm$/, type:'asset/resource' },
146
163
],
147
164
},
165
+
devServer: {
166
+
headers: {
167
+
'Cross-Origin-Opener-Policy':'same-origin',
168
+
'Cross-Origin-Embedder-Policy':'credentialless',
169
+
},
170
+
},
148
171
};
149
172
```
150
173
174
+
> **Safari/iOS:** Safari does not support `credentialless` COEP. Use the COI service worker pattern shown in the [demo app](../../examples/web/RunAnywhereAI/) — it intercepts responses and injects `require-corp` headers at runtime.
|`AudioFileLoader`| Audio file loading and decoding |
685
724
686
725
---
687
726
@@ -715,6 +754,18 @@ Yes. Any GGUF-format model compatible with llama.cpp works for LLM/VLM. STT mode
715
754
716
755
## Troubleshooting
717
756
757
+
### "Failed to fetch dynamically imported module" / WASM not loading (Vite)
758
+
759
+
**Cause:** Vite pre-bundles npm dependencies into `.vite/deps/`, which breaks the relative `import.meta.url` paths used by `@runanywhere/web-llamacpp` and `@runanywhere/web-onnx` to locate their WASM files.
760
+
761
+
**Fix:** Add both packages to `optimizeDeps.exclude` in your `vite.config.ts`:
LLM, VLM, tool calling, structured output, embeddings, and diffusion backend for the [RunAnywhere Web SDK](https://www.npmjs.com/package/@runanywhere/web) — powered by [llama.cpp](https://github.com/ggerganov/llama.cpp) compiled to WebAssembly.
The SDK automatically selects the WebGPU variant when available, falling back to CPU.
57
+
58
+
Configure your bundler to serve these as static assets — see the [main SDK README](https://www.npmjs.com/package/@runanywhere/web) for Vite/Webpack examples.
59
+
60
+
> **Warning (Vite):** You must add `@runanywhere/web-llamacpp` to [`optimizeDeps.exclude`](https://vite.dev/config/dep-optimization-options#optimizedeps-exclude) in your `vite.config.ts`. Vite's pre-bundling breaks the `import.meta.url` paths the SDK uses to locate WASM files. See the [main SDK README](https://www.npmjs.com/package/@runanywhere/web#serve-wasm-files--cross-origin-isolation) for the full Vite config.
61
+
62
+
## Cross-Origin Isolation
63
+
64
+
Multi-threaded WASM requires `SharedArrayBuffer`, which needs Cross-Origin Isolation headers:
65
+
66
+
```
67
+
Cross-Origin-Opener-Policy: same-origin
68
+
Cross-Origin-Embedder-Policy: credentialless
69
+
```
70
+
71
+
See the [main SDK docs](https://www.npmjs.com/package/@runanywhere/web#cross-origin-isolation-headers) for platform-specific configuration.
0 commit comments