supabase

How do I generate types with Supabase locally (i.e. not hosted with Supabase)?


I've installed Supabase locally on my dev machine (and plan to deploy it to a non-Supabase host). So far, everything with Supabase itself has worked great (e.g. I can navigate to http://127.0.0.1:54323/ to see the "Studio").

However, whenever I try to generate types for my client, I get a confusing error:

$ npx supabase gen types typescript 

Access token not provided. Supply an access token by running supabase login or setting the SUPABASE_ACCESS_TOKEN environment variable.

I don't have an access token, and since I'm self-hosted I can't get one. I don't understand why I'd even need one just to generate types (that has nothing to do with my choice of hosts).

Does anyone know how I can generate types locally?

I thought perhaps the environmental variables from my .env.local weren't being accessed, so I tried adding them at the command line:

$ SUPABASE_URL=http://127.0.0.1:54321 SUPABASE_KEY=1234_MY_SECRET_KEY_5678 npx supabase gen types typescript 

However, I still got the same error.


Solution

  • If you have the CLi installed you can run with the --local flag as indicated in the comment from first last

    npx supabase gen types --local

    But if you are self-hosting and want to generate it based on the hosted elsewhere, then you can also pass the DB-URL: --db-url flag.

    Note that you can also generate types for Swift and Typescript:

    --lang <[ typescript | swift ]>

    All details are available on the docs