Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Handling ESModule library: yjs

discord user avatar
alessiogr
2 years ago
4

So I've added this library which internally uses yjs (

https://github.com/yjs/yjs

) to my payload project - and it's throwing these lovely esmodule errors.



How could I fix those?



Not sure if

https://payloadcms.com/docs/admin/webpack#aliasing-server-only-modules

is the problem - the error messages are babbling something about esmodules. But I'm not sure what I'd even put as an alias there

  • default discord avatar
    damnstaychill2 years ago

    Not sure if it'll work with payload being CJS and the lib being ESM but i'm not super familiar with those details. I think the webpack alias is only for code you only want ran on the server and not the client

  • discord user avatar
    alessiogr
    2 years ago

    that coould be the case too - maybe the library has some code which runs on the server. I've seen that error on 2 different libraries which import something related to yjs



    no idea how the hell I'd alias that, though

  • default discord avatar
    damnstaychill2 years ago

    Aliasing the top level library works for me, i had a similary issue with a JWT / Cookie library



    The strange part was I had to import the server library into a file and export it from that file. Then my app code would import that file/ I aliased that file vs the library directly

  • discord user avatar
    alessiogr
    2 years ago

    This seeems to have been the fix for some reason. Wasnt related to server-only stuff at all apparently

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.