y-memory
raw JSON → 8.0.9 verified Sat May 09 auth: no javascript
In-memory database adapter for Yjs, version 8.0.9. It provides a lightweight, ephemeral storage backend for collaborative editing with Yjs, discarding all data upon session end. Best for prototyping or stateless scenarios. Works in all browsers with fast access. Unlike persistent adapters (e.g., y-leveldb), it requires no external database setup. Released under MIT.
Common errors
error Error: Cannot find module 'y-memory' ↓
cause Missing import or npm install.
fix
Run
npm install y-memory and add import 'y-memory' at the top of your file. error TypeError: Y is not a function ↓
cause Trying to use Y() constructor in Yjs v13+ where it's removed.
fix
Use
new Y.Doc() instead of Y({...}). error Error: Yjs version must be between 9.0.0 and 14.0.0 ↓
cause Incompatible Yjs version.
fix
Update Yjs to version 9.0.0-13.x.x with
npm install yjs@^13.0.0. Warnings
deprecated The Y() constructor with db adapter config is deprecated; use Y.Doc() directly in Yjs v13+. ↓
fix Use `new Y.Doc()` and manage persistence separately.
gotcha Data is lost when page is refreshed; memory adapter does not persist. ↓
fix Use a persistent adapter like y-indexeddb or y-leveldb for permanent storage.
breaking y-memory v8 only works with Yjs >=9.0.0 <14.0.0; older versions incompatible. ↓
fix Ensure Yjs version is >=9.0.0 and <14.0.0.
deprecated Bower installation is deprecated; use npm or yarn. ↓
fix Use `npm install y-memory` instead.
Install
npm install y-memory yarn add y-memory pnpm add y-memory Imports
- y-memory wrong
const memory = require('y-memory')correctimport 'y-memory' - Yjs wrong
const Y = require('yjs')correctimport * as Y from 'yjs' - Y wrong
new Yjs({ db: { name: 'memory' } })correctY({ db: { name: 'memory' } })
Quickstart
// Install: npm install yjs y-memory
import * as Y from 'yjs';
import 'y-memory';
// Initialize Yjs with memory adapter
const y = new Y.Doc();
const yarray = y.getArray('myarray');
yarray.insert(0, ['hello']);
// Or use the legacy Y() constructor (deprecated but still works)
// Y({ db: { name: 'memory' } }).then(y => { ... });
console.log(yarray.toArray()); // ['hello']