Closed sammacbeth closed 4 years ago
y-protocols is esm module that should work in nodejs (https://nodejs.org/api/esm.html). In node >= 13 you can simply do import * as Awareness from 'y-protocols/awareness.js
.
But I still recommend that you export a esm module and a cjs module. The esm module should point to y-protocols/awareness.js
and the cjs module should point to y-protocols/dist/awareness.cjs
.
I had some issues trying to use this module in a typescript project. This is because there is no 'main', so deep imports (like
y-protocols/awareness
) cannot be transformed to common JS compatiblerequire
statements (require('y-protocols/awareness')
fails).One possible fix is to have a
index.js
and point correctly to the module and main versions from the package.json. This will enable bundlers to pick the correct version when importing. In commonJS cases,require('y-protocols')
can be used, while es6 modules can still import specific classes.At the moment I'm using the following patch to fix these issues for my use-case, but this only exports the awareness class, so is not a full solution.