Replies: 1 comment
-
Wherever you're using payload, you'll need the Node runtime for now. // In your server component or route handler
export const runtime = "nodejs" There is one other thing you could try: // in next.config.js/mjs
{
experimental: {
serverComponentsExternalPackages: ["payload", "sharp"],
},
} For the next config option, try enabling both runtime edge and runtime nodejs and see what works. The problem here is that sharp doesn't ship browser/WASM bundle. using serverComponentsExternalPackages should be able to disable the deps optimization allowing you to run payload without sharp executing. If this doesn't work, then what happens is payload is loading sharp pre-emptively, meaning its being loaded regardless of it being used or not. If the above doesn't work, try this. I am not too familiar with payload internals, but if it doesn't call sharp during local API usage then you could leverage SWC transforms to alias it directly:
// in next.config.js/mjs
modularizeImports: {
'sharp': {
transform: 'my-sharp-shim',
skipDefaultConversion: true,
},
}, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there,
I've set up Payload w/ Next.js like in the
nextjs-custom-server
example. Everything works fine and I really like the experience.Albeit, I get an error when trying to use the local API inside next.js server components:
I did some digging and It's probably because the
sharp
dependency does not work within the browser environment. I tried a few proposed solutions, like but to no avail.I see that the example in the custom server repo still uses the
/pages
directory structure and not/app
, so I assume the app router and server components are not yet supported / thought of.I have no issue reverting back to and using the REST API.
I am just curious if someone has run into this particular problem or has a working solution.
Also, this could be a heads-up when making the next release compatible with server side components.
Thanks for the great tool and all your hard work peeps!♥️
Beta Was this translation helpful? Give feedback.
All reactions