Handling ESModule library: yjs

default discord avatar
Alessio 🍣
2 months ago
7

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
    damnstaychill
    2 months 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

  • default discord avatar
    Alessio 🍣
    2 months 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

    WebStorm-EAP_2023-03-10_at_18.21.102x.jpg
  • default discord avatar
    damnstaychill
    2 months 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

  • default discord avatar
    Alessio 🍣
    2 months ago

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

    WebStorm-EAP_2023-03-10_at_19.18.332x.jpg
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.