Based on the knowledge sources, I can help you with running Sharp in Convex actions.
The error you're encountering is related to bundling issues with the Sharp library. Sharp relies on native binaries (libvips) which can cause problems during the bundling process.
Here's what you need to do:
Solution: Use External Packages
Sharp is mentioned in the documentation as an example of a library with dynamic dependencies. You can resolve this by marking Sharp as an external package, which is a feature available for the Node.js runtime.
Steps to fix:
- Make sure your action file has the
"use node" directive at the top
- Create or update a
convex.json file in the same directory as your package.json
- Add Sharp to the external packages configuration:
{
"node": {
"externalPackages": ["sharp"]
}
}
Alternatively, you can mark all dependencies as external:
{
"node": {
"externalPackages": ["*"]
}
}
When you mark a package as external, it won't be bundled by esbuild. Instead, it will be installed from npm on the server the first time you push code that uses it, matching the version in your local node_modules folder.
Important notes:
- External packages are only supported in the Node.js runtime, so ensure your action file starts with
"use node";
- After changing your
package.json, run npm install to update your local node_modules before pushing to Convex
- The total size of your source code bundle and external packages cannot exceed 45MB zipped or 240MB unzipped