Hello everyone, first of all I would like to thank @dmonad and this entire community for the great work done with yjs and its entire ecosystem. Second, I would like to clarify that my English is not perfect so I apologize if I make any mistakes. I’d also like to clarify that I’ve never published npm packages before, much less hybrid packages (so I’m pretty new to this) and I’m currently doing a yjs implementation with socket.io
that I’d like to share via an hybrid npm package.
I would like to know if someone could help me with the necessary or recommended configuration to publish this module that I called “y-socket.io
” as a hybrid package (By configuration I mean package.json, tsconfig.json and tsup.config.ts file), I already have some of this configuration implemented but I’m not sure if what I did is right.
In addition to the above, I have the following problem. I already have most of the necessary code base (server side and provider for client), since I was inspired by the y-websocket module. However, I get the error “Yjs was already imported. #438”. I already checked yjs issue #438, but I don’t quite understand how to identify the problem in my case and how to solve it.
Description of the situation:
1- I install the package locally in a project where the client-side implementation will be (because in this package I have the necessary code for the server and I also have the provider for the client), in which, in my case I use react.
2- I run “npm run build
” and then “npm start
” in the “y-socket.io
” package to run the server, since inside the “y-socket.io
” package I have an example server with express (I plan remove express afterwards, I’m just using it since it’s more comfortable for me) in the “example” folder.
3- I run the react project (or some client implementation), in which I use yjs and link a yjs document through the SocketIOProvider (provider included in “y-socket.io
”)
4- When I open two tabs in the browser (to simulate more than one user connected to the same document) the error “Yjs was already imported” appears in the console. and when I try to modify the document through the different browser tabs (clients) it works in a faulty way or simply does not synchronize.
5- Considering issue #438 in the YJS repository, I have two suspicions:
5.1- I suspect that the problem is generated by the SocketIOProvider, since it is importing YJS and in the client project (react in my case) I am also importing YJS (in the same version, v13.5.41). If this were to be the problem, I do not understand how I can solve it and I would like to know if someone can guide me to solve this.
5.2- I suspect the problem may be in the package or hybrid build configuration.
5.3- The previous suspicions are also based on the fact that if I implement the SocketIOProvider in the client project without installing the package, that is, using the “provider.ts” file directly in the react project, the message “Yjs was already imported.” it doesn’t show up on console and sync works perfectly.
Considerations:
- I am working with typescript and building with “tsup” to get code for both “commonjs” and “es modules”
- The repository is: GitHub - ivan-topp/y-socket.io: Socket IO Connector for Yjs (Inspired by y-websocket)
I thank you in advance for your time to read my case.
P.S.: I apologize for not having an explanation in the README.md, at the moment I don’t write the README.md completely as I don’t have client side usage examples because basically it is used the same as “y-websocket” and to run the server will simply install the package dependencies (npm install
) and then run the “start” script (npm start
). I honestly didn’t think it was necessary for now, due to the similarity of use it has with “y-websocket” (If you find it necessary I could create a basic one for now), but I promise a detailed README.md when I manage to solve the problem.