#Hi! I’m trying to add a mutation to delete files from Convex storage.

4 messages · Page 1 of 1 (latest)

inner thistle
#

Hi! I’m trying to add a mutation to delete files from Convex storage, but it never appears in the Functions tab and is not callable from the client. Here’s my code in convex/storage.ts:

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

export const deleteStorageFile = mutation({
args: { storageId: v.id("_storage") },
handler: async (ctx, { storageId }) => {
await ctx.storage.delete(storageId);
return { success: true };
},
});

I’ve run npx convex dev and npx convex dev --verbose.
The file is in the convex/ directory.
Other functions in this file (like generateUploadUrl) work fine.
No TypeScript errors.
The function never shows up in the dashboard.
What could cause this mutation to not be registered or visible? What should I do to fix it?

frigid sedgeBOT
#

Hi @inner thistle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Your mutation code for deleting files from Convex storage is correct and matches the documented approach:

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

export const deleteStorageFile = mutation({
  args: { storageId: v.id("_storage") },
  handler: async (ctx, { storageId }) => {
    await ctx.storage.delete(storageId);
    return { success: true };
  },
});

This is the recommended way to delete files from Convex storage using a mutation, and it should appear in the Functions tab and be callable from the client if everything is set up correctly Deleting Files.

Possible reasons your mutation is not showing up:

  1. Wrong working directory:
    If you run npx convex dev from a directory that is not the root of your Convex project (where the convex/ folder is), your functions will not be picked up or deployed. This is a common issue. Double-check by running pwd and ls convex to ensure you are in the correct directory Discord support thread.

  2. Multiple Convex projects or directories:
    If you have multiple projects or repositories sharing the same database, or if your files are not in sync, Convex may not recognize all functions. Make sure you have only one convex/ directory per project and that all files are up to date Discord support thread.

  3. File location and naming:
    The file must be directly inside the convex/ directory or a subdirectory, and not in convex/_generated/. Files in convex/_generated/ are ignored, as shown in your verbose logs.

#
  1. TypeScript/Build issues:
    While you mentioned there are no TypeScript errors, ensure that your file is saved and that there are no hidden build or syntax errors preventing the function from being registered.

What to do:

  • Ensure you are running npx convex dev from the root of your project (where the convex/ folder is).
  • Confirm your mutation file is in the correct location (convex/storage.ts or a subdirectory, but not in _generated).
  • If you have multiple repos or projects, make sure only one is managing the Convex deployment, or follow the guidance for multiple repos.
  • Try making a small edit to the file and saving it, then watch the output of npx convex dev for any errors or deployment logs.

If you follow these steps and your function is still not visible, please double-check the deployment logs for any errors or warnings, and ensure you are viewing the correct deployment in the Convex dashboard.

Let me know if you need more help!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: