K
Join ServerKysely
help
Migration error "TypeError: Cannot read properties of undefined (reading 'getExecutor')"
I am trying to run a migration using Kysely, and its returning this error:
Does anybody have an idea of how to fix this? I can't find any reference to it
I couldn't post the content of my
file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/raw-builder/raw-builder.js:61
: executorProvider.getExecutor();
^
TypeError: Cannot read properties of undefined (reading 'getExecutor')
at RawBuilder.execute (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/raw-builder/raw-builder.js:61:32)
at Object.up (file:///Users/brunocruz/code/look-manager/packages/core/migrations/2023051601_create-product-table.mjs:5:51)
at Migrator.#migrateUp (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/migration/migrator.js:453:33)
at run (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/migration/migrator.js:344:49)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/kysely.js:370:32
at async DefaultConnectionProvider.provideConnection (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/driver/default-connection-provider.js:10:20)
at async Migrator.#migrate (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/migration/migrator.js:184:20)
at async migrateToLatest (file:///Users/brunocruz/code/look-manager/packages/core/scripts/migrate-to-latest.js:34:30)
Does anybody have an idea of how to fix this? I can't find any reference to it
I couldn't post the content of my
migrate-to-latest.js
and my migration files, because of char limit.Update: I changed my code slightly and am getting a different error.
after adding
But I'm still getting an error:
after adding
db
:await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);
But I'm still getting an error:
`
failed to execute migration "2023051601_create-product-table"
failed to migrate
Error: invalid immediate value
at PostgresQueryCompiler.appendImmediateValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:976:19)
at PostgresQueryCompiler.visitValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:260:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitDefaultValue (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:812:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.visitColumnDefinition (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:365:18)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
at PostgresQueryCompiler.compileList (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:115:18)
at PostgresQueryCompiler.visitCreateTable (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/query-compiler/default-query-compiler.js:337:14)
at PostgresQueryCompiler.visitNode (file:///Users/brunocruz/code/look-manager/node_modules/kysely/dist/esm/operation-node/operation-node-visitor.js:90:34)
`You have two (or more) incompatible versions of Kysely and you are mixing parts of them.
How so? I haven't installed Kysely, it was automatically installed from SST. How can I fix it?
I don't know how to fix it. I haven't used SST. But this error keeps popping up and the reason is always the same.
In your example
db
probably comes from a different Kysely package than the sql
template tag.this is my full example:
am I using the wrong package?
import { sql } from "kysely";
export async function up(db) {
// create extension for uuid
await sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`.execute(db);
// create product table
await db.schema
.createTable("product")
.addColumn("id", "uuid", (col) =>
col.primaryKey().defaultTo(sql`uuid_generate_v4()`)
)
.addColumn("name", "text", (col) => col.notNull())
.addColumn("sku", "text")
.addColumn("brand", "text")
.addColumn("store", "text", (col) => col.notNull())
.addColumn("store_url", "text", (col) => col.notNull())
.addColumn("description", "text")
// .addColumn("old_price", "decimal(12,2)", (col) => col.notNull())
// .addColumn("price", "decimal(12,2)", (col) => col.notNull())
.addColumn("old_price", "decimal", (col) => col.notNull())
.addColumn("price", "decimal", (col) => col.notNull())
.addColumn("currency", "text", (col) => col.notNull())
.addColumn("installments_quantity", "text")
.addColumn("installments_value", "text")
.addColumn("available", "boolean", (col) => col.defaultTo(false))
.addColumn("sizes", "jsonb", (col) => col.defaultTo([]))
.addColumn("images", "jsonb", (col) => col.defaultTo([]))
.addColumn("created_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.addColumn("updated_at", "timestamp", (col) => col.defaultTo(sql`now()`))
.$call((qb) => {
console.log(qb.compile());
return qb;
})
.execute();
}
export async function down(db) {
await db.schema.dropTable("product").execute(db);
}
am I using the wrong package?
and this is my
migrate-to-latest.js
file:import {
FileMigrationProvider,
Kysely,
Migrator,
PostgresDialect,
} from "kysely";
import pg from "pg";
import { promises as fs } from "fs";
import path from "path";
export async function migrateToLatest() {
const __dirname = path.resolve(path.dirname(""));
const db = new Kysely({
dialect: new PostgresDialect({
pool: new pg.Pool({
host: "localhost",
port: 5432,
user: "postgres",
password: "postgres",
database: "postgres",
}),
}),
});
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.join(__dirname, "packages/core/migrations"),
}),
});
const { error, results } = await migrator.migrateToLatest();
results?.forEach((it) => {
if (it.status === "Success") {
console.log(`migration "${it.migrationName}" was executed successfully`);
} else if (it.status === "Error") {
console.error(`failed to execute migration "${it.migrationName}"`);
}
});
if (error) {
console.error("failed to migrate");
console.error(error);
process.exit(1);
}
return db;
}
migrateToLatest();
How should I know that? I don't know where
To make sure we are dealing with two different versions, add this at the top of the script
and add this to the script
if it prints
db
comes and where kysely
points. It depends on your configuration.To make sure we are dealing with two different versions, add this at the top of the script
import { sql, Kysely } from "kysely";
and add this to the script
console.log(db.constructor === Kysely)
if it prints
true
I'm wrong, if false
db
doesn't come from the imported kysely.It prints false
Actually you can also do
db instanceof Kysely
Yep. So somehow somewhere, there's two versions. The kysely you import in the script is not the same that was used to create
db
.Modern versions of kysely should already be able to deal with most of these mixed versions issues. You could start by updating the SST packages
Thank you for your help so far. Maybe installing kysely package directly can help. I'll report back what I find.
Switching to
pnpm
and enforcing a kysely version at package.json
might fix itpnpm hoists packages and dries up your node_modules by default, so there would be just 1 copy of kysely once you force kysely v0.24.2, 🤞🏻