#Types generated from tables are not available when building in production

1 messages · Page 1 of 1 (latest)

plain spindle
#

I'm running a build on Netlify for the first time, and it's not seeing the generated tables in the database.

6:32:48 AM: $ astro check && astro build --remote
6:32:49 AM: 10:32:49 [check] Getting diagnostics for Astro files in /opt/build/repo...
6:32:51 AM: db/seed.ts:2:14 - error ts(2305): Module '"astro:db"' has no exported member 'User'.
6:32:51 AM: 2 import { db, User } from 'astro:db';
6:32:51 AM: 

I have set ASTRO_STUDIO_APP_TOKEN environment variable and using the command astro check && astro build --remote.

heavy quartzBOT
#

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

#

The error message you're seeing indicates that TypeScript is unable to find the User export from the astro:db module. This could be due to a few reasons:

  1. Astro DB types are not generated before the build: Astro generates types for your database tables when you run the dev or build commands. If the types are not generated before the build, you might see errors like this. Make sure you're running astro dev or astro build before trying to use the types.

  2. The User table is not defined in your database schema: If the User table is not defined in your database schema, TypeScript won't be able to find it. Make sure you've defined the User table in your database schema.

  3. TypeScript configuration issues: If your TypeScript configuration is not set up correctly, it might not be able to find the types generated by Astro. Make sure your tsconfig.json file is set up correctly.

If you're still having issues, it might be helpful to look at some of the open and closed issues related to Astro DB and TypeScript on the Astro GitHub repository (https://github.com/withastro/astro/issues?q=is%3Aissue+astro%3Adb+typescript+). You might find others who have encountered similar issues and see how they resolved them.

Also, be aware that using the --remote flag in your build command will connect to a live production database, and all inserts, updates, or deletions will be persisted. Make sure you're okay with this before running the command (source (https://docs.astro.build/en/guides/astro-db#connect-to-astro-studio)).

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