snoww
snoww3w ago

sharp won't work

i'm about to go to sleep so sorry for lack of detail, will update in the morning logs
[convex] - Preparing Convex functions...
[convex]
[convex] ✖ Error: Unable to start push to https://...-...-47.convex.cloud
[convex] ✖ Error fetching POST https://...-...-47.convex.cloud/api/deploy2/start_push 400 Bad Request: InvalidModules: Hit an error while pushing:
[convex] Uncaught Failed to analyze addImageSizing.js: Could not load the "sharp" module using the linux-arm64 runtime
[convex] ERR_DLOPEN_FAILED: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /tmp/external_deps/5f59b96c-e51c-4f71-9d87-a1e1d93dba62/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node)
[convex] Possible solutions:
[convex] - Ensure optional dependencies can be installed:
[convex] npm install --include=optional sharp
[convex] - Ensure your package manager supports multi-platform installation:
[convex] See https://sharp.pixelplumbing.com/install#cross-platform
[convex] - Add platform-specific dependencies:
[convex] npm install --os=linux --cpu=arm64 sharp
[convex] - Consult the installation documentation:
[convex] See https://sharp.pixelplumbing.com/install
[convex] - Preparing Convex functions...
[convex]
[convex] ✖ Error: Unable to start push to https://...-...-47.convex.cloud
[convex] ✖ Error fetching POST https://...-...-47.convex.cloud/api/deploy2/start_push 400 Bad Request: InvalidModules: Hit an error while pushing:
[convex] Uncaught Failed to analyze addImageSizing.js: Could not load the "sharp" module using the linux-arm64 runtime
[convex] ERR_DLOPEN_FAILED: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /tmp/external_deps/5f59b96c-e51c-4f71-9d87-a1e1d93dba62/node_modules/@img/sharp-linux-arm64/lib/sharp-linux-arm64.node)
[convex] Possible solutions:
[convex] - Ensure optional dependencies can be installed:
[convex] npm install --include=optional sharp
[convex] - Ensure your package manager supports multi-platform installation:
[convex] See https://sharp.pixelplumbing.com/install#cross-platform
[convex] - Add platform-specific dependencies:
[convex] npm install --os=linux --cpu=arm64 sharp
[convex] - Consult the installation documentation:
[convex] See https://sharp.pixelplumbing.com/install
using pnpm, "sharp": "^0.34.1",
6 Replies
Convex Bot
Convex Bot3w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
snoww
snowwOP3w ago
function using sharp
"use node";

import { internalMutation } from "./_generated/server";
import { v } from "convex/values";
import sharp from "sharp";

export const addImageSizing = internalMutation({
args: {
itemId: v.id("closet"),
},
handler: async (ctx, { itemId }) => {
const item = await ctx.db.get(itemId);
if (!item || !item.imageId) throw new Error("Item or image not found");

const imageUrl = await ctx.storage.getUrl(item.imageId);
if (!imageUrl) throw new Error("Image URL not found");

const response = await fetch(imageUrl);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

const metadata = await sharp(buffer).metadata();

await ctx.db.patch(itemId, {
width: metadata.width,
height: metadata.height,
});
},
});
"use node";

import { internalMutation } from "./_generated/server";
import { v } from "convex/values";
import sharp from "sharp";

export const addImageSizing = internalMutation({
args: {
itemId: v.id("closet"),
},
handler: async (ctx, { itemId }) => {
const item = await ctx.db.get(itemId);
if (!item || !item.imageId) throw new Error("Item or image not found");

const imageUrl = await ctx.storage.getUrl(item.imageId);
if (!imageUrl) throw new Error("Image URL not found");

const response = await fetch(imageUrl);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

const metadata = await sharp(buffer).metadata();

await ctx.db.patch(itemId, {
width: metadata.width,
height: metadata.height,
});
},
});
RJ
RJ3w ago
Did you add it as an external package? https://docs.convex.dev/functions/bundling#external-packages e.g. in your convex.json
{
"node": {
"externalPackages": ["sharp"]
}
}
{
"node": {
"externalPackages": ["sharp"]
}
}
snoww
snowwOP3w ago
yes i did, sorry didn't say that i'm on a windows system so i think this is part of the problem i downgraded to 0.33.5 of sharp and it worked, my previous code was also broken, only actions can run under node so i had to refactor the code to take url and just return the metadata
"use node";

import { internalAction } from "./_generated/server";
import { v } from "convex/values";
import sharp from "sharp";

export const getImageMetadata = internalAction({
args: {
url: v.string(),
},
handler: async (ctx, { url }) => {
const response = await fetch(url);

if (!response.ok) throw new Error("Image not found");
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

return await sharp(buffer).metadata();
},
});
"use node";

import { internalAction } from "./_generated/server";
import { v } from "convex/values";
import sharp from "sharp";

export const getImageMetadata = internalAction({
args: {
url: v.string(),
},
handler: async (ctx, { url }) => {
const response = await fetch(url);

if (!response.ok) throw new Error("Image not found");
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);

return await sharp(buffer).metadata();
},
});
RJ
RJ3w ago
I wouldn't think this has anything to do with Windows, as the bundling happens on Convex servers But it does sound like maybe it's somehow a sharp version issue I use 0.33.5 and I don't have any issues
mikeysee
mikeysee2d ago
I just experienced exactly the same thing

Did you find this page helpful?