Issues with payload in Next.js using the 'next-payload' plugin

default discord avatar
teamkube
3 months ago
10

I just can't get it to work properly. Every HMR (hot reload) on a component that imports the payload client (the

getPayloadClient

you get

from next-payload install

) crashes the app with the following error:



Unhandled Runtime Error


Error: Cannot overwrite _preferences model once compiled.


This seems to have something to do with mongoose used internally by payload

  • default discord avatar
    notchr
    3 months ago

    Hey @teamkube welcome in - this issue has been mentioned previously here:

    https://discord.com/channels/967097582721572934/1112747743472005215/1112748016592486420


    Though, I don't seen a resolution posted...



    Seems like a version error? And yes, related to the preference collection



    The version chart posted by @zeniodev lists where this issue occurs,


    13.4.0 ✅ works


    13.4.1 ✅ works


    13.4.2 ✅ works


    13.4.3 ✅ works


    13.4.4 ⚠️ Cannot overwrite _preferences model once compiled.



    Does someone from the Payload team have any additional information regarding this issue?

  • default discord avatar
    teamkube
    3 months ago

    I tried the version used by the demo application

    https://github.com/payloadcms/next-payload-demo


    13.2.4-canary.6 that is a lot older than 13.4.3



    maybe something got cached, ill try again with 13.4.3

  • default discord avatar
    jarrod69420
    3 months ago

    I will look into this today

  • default discord avatar
    teamkube
    3 months ago

    setting Next to 13.4.3 + deleting ./next , ./node_modules and my package.lock solved it



    thanks a lot

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.