sugarlabs / musicblocks

Music Blocks -- A musical microworld
https://musicblocks.sugarlabs.org/
GNU Affero General Public License v3.0
539 stars 726 forks source link

[3851] - Add/yjs socketio #3923

Open apsinghdev opened 4 days ago

apsinghdev commented 4 days ago

Addresses: #3851

I am trying to install and setup yjs and y-socket.io libraries in Music Blocks. Though I've installed the libraries using npm but I am not able to access them in the collaboration.js file or anywhere else.

I have tried import * as Y from "yjs" (CommonJS) and const Y = require("yjs")" (ES module) both the methods but getting errors. Using CommonJS, I am getting the error Cannot use import statement outside a module, and in ES module, I am getting require not defined

Current Behavior

When I log Console.log(Y), it gives me not defined error.

Expected Behavior

While if library is imported, I will get a module as a result of Console.log(Y)

If you can provide any insight to sort this issue out, It'd be really helpful.

codewiz commented 3 days ago

I have tried import * as Y from "yjs" (CommonJS) and const Y = require("yjs")" (ES module) both the methods but getting errors. Using CommonJS, I am getting the error Cannot use import statement outside a module, and in ES module, I am getting require not defined

I wonder if you need to say type="module" in order to use import in collaboarion.js?

<script type="module" src="./js/collaboration/collaboration.js"></script>

Just an idea, I'm not really a web developer. I found this suggestion in Mozilla's official JS documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#applying_the_module_to_your_html

The same doc also recommends the .mjs extension for modules, but I have never seen anyone use it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#aside_%E2%80%94_.mjs_versus_.js

apsinghdev commented 2 hours ago

@walterbender made commits fixing the installation error, please have a look