drizzle-kit throwing await is not available in the configured target environment

Hi, when using the generate:pg command i am getting this error: 'Top-level await is not available in the configured target environment ("node14")'
1 Reply
potato
potato15mo ago
Schema Code: 🫡 import { pgEnum, pgTable, serial, integer, uniqueIndex, varchar } from 'drizzle-orm/pg-core'; // declaring enum in database export const popularityEnum = pgEnum('popularity', ['unknown', 'known', 'popular']); export const countries = pgTable('countries', { id: serial('id').primaryKey(), name: varchar('name', { length: 256 }), }, (countries) => { return { nameIndex: uniqueIndex('name_idx').on(countries.name), } }); export const cities = pgTable('cities', { id: serial('id').primaryKey(), name: varchar('name', { length: 256 }), countryId: integer('country_id').references(() => countries.id), popularity: popularityEnum('popularity'), }); DB.ts code: 🤠 // db.ts import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core'; import { drizzle } from 'drizzle-orm/node-postgres'; import { Client } from 'pg'; import { env } from "../env.mjs"; import { countries } from './schema'; const client = new Client({ connectionString: env.POSTGRES_URL, }); await client.connect(); const db = drizzle(client); const allCountries = await db.select().from(countries); Complete error code:❌ Error: Transform failed with 2 errors: C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\src\db\db.ts:13:0: ERROR: Top-level await is not available in the configured target environment ("node14") C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\src\db\db.ts:17:21: ERROR: Top-level await is not available in the configured target environment ("node14") at failureErrorWithLog (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\esbuild\lib\main.js:1575:15) at C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\esbuild\lib\main.js:814:29 at responseCallbacks.<computed> (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\esbuild\lib\main.js:680:9) at handleIncomingPacket (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\esbuild\lib\main.js:735:9) at Socket.readFromStdout (C:\Users\Abdul\Documents\GitHub\bodyshop-mgmt\node_modules\esbuild\lib\main.js:656:7) at Socket.emit (node:events:513:28) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:297:9) at Readable.push (node:internal/streams/readable:234:10) at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) { errors: [ { detail: undefined, id: '', location: [Object], notes: [], pluginName: '', text: 'Top-level await is not available in the configured target environment ("node14")' }, { detail: undefined, id: '', location: [Object], notes: [], pluginName: '', text: 'Top-level await is not available in the configured target environment ("node14")' } ], warnings: [] } never mind, fixed it (t3 stack doesnt have top-level await configured by default), however ran into the import zod issue with the environment variables
Want results from more Discord servers?
Add your server
More Posts