#export const api = anyApi;

9 messages · Page 1 of 1 (latest)

void tinsel
#

Why could api generated in _generated be empty ?

serene magnetBOT
#

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

#

api in convex/_generated/api is never actually empty at runtime – it’s just a Proxy over anyApi from convex/server. That proxy always lets you write things like api.foo.bar.baz without throwing; it doesn’t “contain” functions as own properties. [In search of magic; anyApi var]

Because of that:

  • At runtime:

    • api is a Proxy → Object.keys(api) or Object.entries(api) is empty, so it looks empty when you inspect it. [How to get schema]
    • Accessing api.some.module.func returns another Proxy / function reference, not a stored property.
  • At the type level:

    • api.d.ts declares
      declare const fullApi: ApiFromModules<{ ... all your convex modules ... }>;
      export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
      
      so the TypeScript type of api is built from your modules via ApiFromModules and FilterApi. [server type aliases; TS secrets]
    • If your IDE only shows api as FilterApi<...> without expanding, that’s an editor/TS config/intellisense limitation, not that api is empty. This came up in the “No types in IDE” Discord thread. [No types in IDE]

So “api is empty” usually means one of:

#
  1. Runtime inspection (e.g. Object.entries(api)) – expected to show nothing due to the Proxy design.
  2. Editor not expanding types – but api.d.ts still has all your modules/functions listed.

If what you’re seeing is different (e.g. api.d.ts doesn’t list your modules at all), that isn’t covered in the docs here; the sources don’t describe a case where _generated/api is truly empty.

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

#

@void tinsel Kapa.ai is still learning and improving, please let me know how I did by reacting below.

void tinsel
#

@serene magnet like export const api = anyApi;

serene magnetBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

export const api = anyApi; in _generated/api.js is expected and does not mean your API is “empty”.

From the docs and stack article:

  • The generated api.js just does:

    import { anyApi } from "convex/server";
    
    export const api = anyApi;
    export const internal = anyApi;
    

    at runtime. [Generated api.js; Code spelunking]

  • anyApi is a Proxy created by createApi() that fabricates function references on the fly when you access properties – it doesn’t have real enumerable properties. So things like Object.entries(api) will return [], which can make it look empty. [anyApi var; In search of magic]

The types for api live in api.d.ts, not api.js. That file declares:

declare const fullApi: ApiFromModules<{ /* all your convex modules */ }>;
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;

so TypeScript knows the full tree of modules and functions even though the runtime object is just anyApi. [Server type aliases; TS secrets]

#

If your concern is “why does api.js not have a big object literal of my functions and instead just export const api = anyApi;?”: that is by design. The structure comes from types (api.d.ts) plus the Proxy behavior of anyApi, not from a concrete JS object.

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