drizzle-kit failing with Top-level await is currently not supported with the "cjs" output format

Can't seem to get drizzle-kit generate to run? PS \sst\packages\core> node --version v18.17.1 PS \sst\packages\core> yarn drizzle-kit generate:pg yarn run v1.22.19 warning package.json: No license field $ \sst\node_modules.bin\drizzle-kit generate:pg drizzle-kit: v0.19.13 drizzle-orm: v0.28.5 No config path provided, using default 'drizzle.config.ts' Reading config file 'C:\git\triad\sst-triad\packages\core\drizzle.config.ts' Error: Transform failed with 1 error: C:\git\triad\sst-triad\node_modules\sst\node\util\index.js:15:21: ERROR: Top-level await is currently not supported with the "cjs" output format
3 Replies
Angelelz
Angelelz15mo ago
Is your schema running any kind of async function? Or is it importing from somewhere where a async function is run?
patrick
patrickOP15mo ago
it exports a couple of async functions... import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core"; import { db } from "../db"; export const users = pgTable("users", { id: serial("id").primaryKey(), givenName: text("givenName"), surname: text("surname"), email: varchar("email"), }); export type User = typeof users.$inferSelect; // return type when queried export type NewUser = typeof users.$inferInsert; // insert type export async function getUsers(): Promise<User[]> { return await db.select().from(users); } export async function insertUser(user: NewUser): Promise<User[]> { return db.insert(users).values(user).returning(); } ahh, it seems if i remove my async functions to another file, that fixes it...
Angelelz
Angelelz15mo ago
Yeah, it's an antipattern to export or do anything other that the schema in the schema file
Want results from more Discord servers?
Add your server