Closed flaviouk closed 3 years ago
What is the error message?
If you want to import the cjs file, you can do so. Use lib0/dist/sync.cjs
instead.
Did you try to run this locally?
I did try with cjs but it also didn't work, are you able to hack the repo I sent with a solution that doesn't throw errors?
Btw this is for the y-protocols package not lib0
Alright got it working: https://github.com/flaviouk/y-protocols-import/commit/684c1ebbd92ab6f9fc442c114e180abec5f6a617
I hate configs
Okay after battling with esm issues in jest for a little longer, I found a way around it:
moduleNameMapper: {
'^y-protocols/(.*)$': 'y-protocols/dist/$1.cjs',
'^lib0/dist/(.*).cjs$': 'lib0/dist/$1.cjs',
'^lib0/(.*)$': 'lib0/dist/$1.cjs',
},
Not a big fan of having to do this tbh @dmonad
Can't you just import 'y-protocols/sync'
? It does work for me in webpack, rollup, npm, and native esm. What is this about?
Importing awareness actually, but in jest it was pointing to the esm version which is not supported, so these module mappers in the jest config make it work somehow, esm tooling is complicated at the moment
This seems to be more an issue with jest than with esm tooling.
If jest would support either esm modules or at least module mapping, then it should just work. We can only fix this by making y-protocols a cjs module (which is obviously not an option).
Correct yes! But at the same time, I’ve seen some of your rollup configs which have some exceptions to these modules as well, not great imo. I’ve never had issues when I’ve used a single file export type builder like https://github.com/jaredpalmer/tsdx, tooling get’s confused when you export multiple files on a single package, references become broken unless you fix it manually via config.. Maybe its the case for @yjs/protocol-awareness instead of y-protocol/awareness
I removed these rollup configurations because the problem is now widely solved through module mapping.
Also, I only needed to rewrite the paths because I'm generating a CJS module based on the esm module. For compatibility, I needed to rewrite every path to their cjs version.
Describe the bug Can't import in a barebones typescript environment
To Reproduce Steps to reproduce the behavior:
Expected behavior No errors
Environment Information