y-websocket
y-websocket copied to clipboard
Next major release: Make this a proper esm module
Note to myself:
Make this a proper ESM module by setting type: "module"
in package.json. Currently, the bin
folder contains commonjs modules (with file ending of .js
) and the src
folder contains ecmascript modules (also with the file ending .js
). This is invalid to the spec.
But to keep compatibility, we have to keep the current format until the next major release because some projects require the bin
module using an absolute path.
Kind of related (or maybe add another issue/ simple pull request?), when I build my app for production, it is throwing an error trying to import y-websocket/bin/utils
:
Error: Missing "./bin/utils" export in "y-websocket" package
because it is not listed in the exports
of the package.json
.
Ah I nvm, I read on Gitter, that it is recommended to basically clone the repository to implement your own custom y-websocket server right?
Related to this, when I tried to install [email protected]
when I run it I get this

This is not an issue with [email protected]
Is it possible to upgrade the package.json to use "type": "module"
? Not sure what it breaks in downstream repos but I'm willing to fix it if I know what gets broken. Otherwise my svelte-kit project will not build unless I either remove the "exports" block manually or set the type myself by some hacky script. Maybe there's a config option to force a resolution on package basis but I'd rather fix it here.
This issue makes yjs impossible to use with the latest Svelte/SvelteKit apart from very hard and hacky workarounds. I'd really like the major version bump that dmonad mentions above :)
Edit: To add more info to TeemuKoivisto's post above, I hacked the package.json to use "type": "module"
, however that caused a "multiple versions of yjs are loaded, this could cause issues" at runtime.
@nokola I'll make a PR and see what's the reception. And my current solution has been just pinning the y-websocket version to 1.3.14
.
Any updates to this?
I'm forced to use an ugly shim because utils.js
does not export Y
.
Alternatively, as a backwards-compatible stop-gap, could Y
perhaps be exported? Probably won't work with everything, but.
Stop-gap for those who ended up here:
Create a shim with the *.cjs
, e.g. yjs-shim.cjs
(note the extension! — this will force Node to fetch the CJS version of yjs
as well).
exports.Y = require('yjs');
… and then import is as normal:
import { Y } from './yjs-shim.cjs';
Hi, it would be great if this were released soon.
Is this stil not updated? What's blocking? I'm also in the situation of having to integrate Y.js to sveltekit.