I'm working on a hook to generate blur hashes when an image is uploaded so I can use them with the Nextjs Image component.
It is pretty simple to generate the blur, but for some reason I keep getting an error when I try to use the
sharp
library. It looks like it is bundled in with Payload, so I'm not sure if there is anything different that I need to do other than importing it into my hook.
The issue seems to happen on this line in the
sharp
library.
// node_modules/detect-libc/lib/detect-libc.js
const childProcess = require('child_process');
The console shows:
Module not found: Error: Can't resolve 'child_process' in '/Users/.../node_modules/detect-libc/lib'
I've tried adding
sharp
to my project, but that didn't seem to help. Uninstalled that package and reinstalled Payload and keep getting the same error. Might just have to use another library, but I would like to use this one since it works well and is already included.
It might be making it into the client bundle. Trying this alias...
https://payloadcms.com/docs/admin/webpack#aliasing-server-only-modules100%
That’s the issue
Heck yeah! the docs make this look really easy, but I'm still on it. Not out of the woods yet haha
What’s not working for ya? What’s your webpack property look like in your payload config?
I got it working! Thanks though. I was trying to reroute a folder, but my syntax must have been off. I am currently just aliasing a single file and it working great.
It would be nice to alias a folder all to one mock file.
I just don't think thats how it works. When webpack traverses the file tree, it looks at all import paths at the top of files and then compares each one with the ones in your resolve.alias and if it finds an alias route, it uses that instead
But now you know how to fix it and will recognize it when others run into it. Glad you were able to solve 🙂
Ok that makes sense. Thanks for the help!
Hi, sorry I am late to topic I hope you can replay, how did you manage to solve this issue in the end, I have the same problem and tried everything…
Thank you in advance
@kristijan007v is sharp making it into the client bundle? it shouldnt
@notchris I think it is, I tried adding it to the externals inside the webpack config for Payload and many other things with no success, I opted in using this library
https://plaiceholder.coafter all
@notchris Thank you for trying to help 🍻
Star
Discord
online
Get dedicated engineering support directly from the Payload team.