Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno - error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace') #11

Closed
bidipeppercrap opened this issue Jan 15, 2024 · 3 comments
Labels
wontfix This will not be worked on

Comments

@bidipeppercrap
Copy link

bidipeppercrap commented Jan 15, 2024

image
image

Spec

Runtime: Deno
Database Provider: Neon

Reproduce:

I run into this error when I try to migrate.

Code

deno.json

{
    "imports": {
        "db/": "./src/db/",
        "kysely": "npm:kysely@^0.27.2",
        "kysely-postgres-js": "npm:kysely-postgres-js@^2.0.0",
        "postgres": "https://deno.land/x/[email protected]/mod.js"
    },
    "tasks": {
        "migrate": "deno run -A ./src/db/migrator.ts"
    }
}

migrator:

import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { promises as fs } from "node:fs";
import { Migrator, FileMigrationProvider } from "kysely";
import { db } from "db/database.ts";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function migrateToLatest() {
    const migrator = new Migrator({
        db,
        provider: new FileMigrationProvider({
            fs,
            path,
            migrationFolder: path.join(__dirname, "./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);
        Deno.exit(1);
    }

    await db.destroy();
}

migrateToLatest();

db instance:

import { Database } from "db/types/index.ts";
import postgres from "postgres";
import { Kysely } from "kysely";
import { PostgresJSDialect } from "kysely-postgres-js";
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";

const env = await load();

const dialect = new PostgresJSDialect({
    postgres: postgres({
        database: env["PGDATABASE"]!,
        host: env["PGHOST"]!,
        user: env["PGUSER"]!,
        password: env["PGPASSWORD"]!,
        port: 5434,
        max: 10,
    })
});

export const db = new Kysely<Database>({
    dialect
});
@bidipeppercrap bidipeppercrap changed the title error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace') Deno - error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace') Jan 15, 2024
@igalklebanov
Copy link
Member

Hey 👋

Print env object, it might have an undefined connection string.
Try npm i [email protected].

@igalklebanov
Copy link
Member

igalklebanov commented Mar 1, 2024

Seems similar to #10. Closing this as it's related to postgres and not kysely-postgres-js.

@igalklebanov igalklebanov added the wontfix This will not be worked on label Mar 26, 2024
@Sleepful
Copy link

very cryptic error yeah, it means the connection to the DB isn't working, in my case I had the wrong port number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants