BettoRaite
BettoRaite
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
Looks good
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
And btw gimme a screen of TS config
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
Try changing to es 2020
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
There should a target option
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
so you either change the ts config or wrap in IIFE
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
same here
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
You see your migration file uses the await in global context
await migrate(db, { migrationsFolder: "./drizzle" }); // <-- not good
await connection.end(); // <-- not good
await migrate(db, { migrationsFolder: "./drizzle" }); // <-- not good
await connection.end(); // <-- not good
possible fix wrap in Immediately Invoked Function Expressions (IIFE) in
import "dotenv/config";
import { migrate } from "drizzle-orm/mysql2/migrator";
import { db, connection } from "./db";

(async()=>{
// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: "./drizzle" });

// Don't forget to close the connection, otherwise the script will hang
await connection.end();
})();
import "dotenv/config";
import { migrate } from "drizzle-orm/mysql2/migrator";
import { db, connection } from "./db";

(async()=>{
// This will run migrations on the database, skipping the ones already applied
await migrate(db, { migrationsFolder: "./drizzle" });

// Don't forget to close the connection, otherwise the script will hang
await connection.end();
})();
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
in common js module system you can't have await keyword in global context
26 replies
DTDrizzle Team
Created by Shayokh on 8/15/2024 in #help
⚠ Error - Top-level await is currently not supported with the "cjs" output format
I think your ts config spits out cjs, that is why
D:\Typescript\drizzle orm\drizzle_test\migrate.ts:6:0: ERROR: Top-level await is currently not supported with the "cjs" output format
D:\Typescript\drizzle orm\drizzle_test\migrate.ts:6:0: ERROR: Top-level await is currently not supported with the "cjs" output format
26 replies