yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
497 stars 256 forks source link

Convert utils.js to part of ES module (and move to src dir?) #105

Open canadaduane opened 2 years ago

canadaduane commented 2 years ago

Is your feature request related to a problem? Please describe.

Our ES server backend (EcmaScript, i.e. preferring "import" over "require") directly imports utils.js:

import * as yws from "y-websocket/bin/utils";

Unfortunately, because utils.js has a const Y = require('yjs') line, it is importing Yjs once as CJS, and then when our server later includes yjs by calling import * as Y from 'yjs', Yjs gets included a 2nd time as a module.

This causes the warning:

Yjs was already imported. Importing different versions of Yjs often leads to issues.

Describe the solution you'd like Would it be possible to refactor such that utils.js is part of the ES module?

Describe alternatives you've considered Currently, we have code duplication that is (probably) causing issues, as the warning suggests. I believe a workaround is to copy/paste the utils.js file and change the require statements to import.