Circular dependency when compiling

Hi -

Hearing all the good things about yjs especially its performance, I tried to work on a simple sample to test yjs out, only quickly (and sadly) running into the problem when compiling the sample codes

import * as Y from 'yjs';
import { IndexeddbPersistence } from 'y-indexeddb';

const ydoc = new Y.Doc();

// this allows you to instantly get the (cached) documents data
const indexeddbProvider = new IndexeddbPersistence('count-demo', ydoc);
indexeddbProvider.whenSynced.then(() => {
  console.log('loaded data from indexed db');
});


// array of numbers which produce a sum
const yarray = ydoc.getArray('count');

// observe changes of the sum
yarray.observe(event => {
  // print updates when the data changes
  console.log(`new sum: ${yarray.toArray().reduce((a, b) => a + b)}`);
});

// add 1 to the sum
yarray.push([1]); // => "new sum: 1"

And the problem lies in the compiling stage shown in the below. Please help. Thanks!

Circular dependency: node_modules/lib0/encoding.js β†’ node_modules/lib0/buffer.js β†’ node_modules/lib0/encoding.js
Circular dependency: node_modules/lib0/buffer.js β†’ node_modules/lib0/decoding.js β†’ node_modules/lib0/buffer.js

Circular dependency: node_modules/lib0/encoding.js β†’ node_modules/lib0/buffer.js β†’ node_modules/lib0/encoding.js
Circular dependency: node_modules/lib0/buffer.js β†’ node_modules/lib0/decoding.js β†’ node_modules/lib0/buffer.js

1 Like

Hi @john,

Circular dependencies are indeed an issue of concern in a lot of cases. But I handle them safely in Yjs and related libs. There are transpilers that show a warning message when they detect circular dependencies. In this case, you really don’t have to worry about it.

If - for some reason - your compiler failed the compilation of Yjs please open a ticket in the Yjs repository and fill out the form. Please also mention which transpiler you are using.

Cheers,
Kevin

Thank you Kevin for your answer. Yeah, it was a warning. The transpiler used was rollup.

Best,
John