TypeError: Cannot read properties of undefined (reading 'dialect')

Hello, I am trying out Drizzle for the first time with javascript and Nodejs. I am trying out the migration part of Drizzle and I have setup everything that the docs said to me. But when I run node db/migrate.js I get the error undefined (reading 'dialect'). Why is this?
// config
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './db/schema.js',
out: './drizzle',
dialect: 'mysql', // 'postgresql' | 'mysql' | 'sqlite'
dbCredentials: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
});
// config
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './db/schema.js',
out: './drizzle',
dialect: 'mysql', // 'postgresql' | 'mysql' | 'sqlite'
dbCredentials: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
},
});
// db.js
const { drizzle } = require('drizzle-orm/mysql2');
const mysql = require('mysql2/promise');
const schema = require('./schema');

module.exports = connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
multipleStatements: true,
});

module.exports = db = drizzle(connection, { schema, mode: 'default' });
// db.js
const { drizzle } = require('drizzle-orm/mysql2');
const mysql = require('mysql2/promise');
const schema = require('./schema');

module.exports = connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
multipleStatements: true,
});

module.exports = db = drizzle(connection, { schema, mode: 'default' });
// migrate.js
require('dotenv').config();
const migrate = require('drizzle-orm/mysql2/migrator').migrate;
const { db, connection } = require('./db');

async function main() {
await migrate(db, { migrationsFolder: './drizzle' });
await connection.end();
}

main().catch(console.error);
// migrate.js
require('dotenv').config();
const migrate = require('drizzle-orm/mysql2/migrator').migrate;
const { db, connection } = require('./db');

async function main() {
await migrate(db, { migrationsFolder: './drizzle' });
await connection.end();
}

main().catch(console.error);
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server