TypeScript compiler would give an error: Module 'yjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
Since you specified "module": "CommonJS", you probably want to do const Y = require('yjs') instead.
I donât advertise the use of commonjs anymore. If you still want to use commonjs, you can (Yjs provides a commonjs bundle), however, you need to adapt all code examples from import to require.
Thank you for replying. May I please ask instead of "module": "CommonJS", what kind of module would you recommend we generate for Node.js applications? Iâve tried changing it to both âESNextâ and âNodeNextâ. Unfortunately neither worked.
@dizy I recommend using a different template for tsconfig. There is something wrong with yours. This one works perfectly. Iâve also seen others that consume yjs without problems (e.g. jupyterlab/jupyterlab).
If you transpile your code before execution, then you should definitely use ESM and transpile to CJS if needed. Otherwise: if you start fresh give ESM a try. Itâs sometimes harder to migrate existing projects.