Uncaught Error: Dynamic require of "events" is not supported

Going through the Hyperdrive Mysql guide and hitting this error consistently. I've got nodejs_compat and compat date set according to the guide(although different guides use different compat dates, I've tried both). Still hitting the error. wrangler.staging.toml: --------------------- name = "[REDACTED]-staging" main = "dist/worker.bundle.js" compatibility_date = "2024-08-21" compatibility_flags = ["nodejs_compat"] [vars] ENVIRONMENT = "staging" [observability.logs] enabled = true invocation_logs = false [[hyperdrive]] binding = "HYPERDRIVE" id = "[REDACTED]" ========================================= database.js: ---------------- import { createConnection } from "mysql2/promise"; export async function getDomainSettings(domain, env) { const connection = await createConnection({ host: env.HYPERDRIVE.host, user: env.HYPERDRIVE.user, password: env.HYPERDRIVE.password, database: env.HYPERDRIVE.database, port: env.HYPERDRIVE.port, // The following line is needed for mysql2 compatibility with Workers // mysql2 uses eval() to optimize result parsing for rows with > 100 columns // Configure mysql2 to use static parsing instead of eval() parsing with disableEval disableEval: true, }); try { // Sample query const [results, fields] = await connection.query("SHOW tables;"); // Clean up the client after the response is returned, before the Worker is killed ctx.waitUntil(connection.end()); return results; } catch (e) { console.error(e); } }
1 Reply
Kaylined
KaylinedOP7mo ago
esbuild issue, not invested enough to figure it out. Works fine with webpack.

Did you find this page helpful?