y-websocket icon indicating copy to clipboard operation
y-websocket copied to clipboard

Next major release: Make this a proper esm module

Open dmonad opened this issue 3 years ago • 9 comments

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.

dmonad avatar May 31 '21 13:05 dmonad

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?

JesseVelden avatar Jun 01 '21 09:06 JesseVelden

Related to this, when I tried to install [email protected] when I run it I get this

Screen Shot 2021-06-07 at 1 48 03 PM

This is not an issue with [email protected]

jperl avatar Jun 07 '21 20:06 jperl

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.

TeemuKoivisto avatar Oct 19 '21 09:10 TeemuKoivisto

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 avatar Nov 28 '21 18:11 nokola

@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.

TeemuKoivisto avatar Nov 29 '21 07:11 TeemuKoivisto

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';

darkuranium avatar Mar 29 '22 15:03 darkuranium

Hi, it would be great if this were released soon.

jsonkao avatar Jan 26 '24 04:01 jsonkao

Is this stil not updated? What's blocking? I'm also in the situation of having to integrate Y.js to sveltekit.

MentalGear avatar Mar 01 '24 14:03 MentalGear