Example failed to run: `pg` does not provide an export named `Pool`
I'm trying to run the example from the
This is my stripped down example:
This is my
Running it:
READMEREADME file. I made a minial version, installed pgpg, @types/pg@types/pg, drizzle-ormdrizzle-orm and drizzle-kitdrizzle-kit and tried to run it via tsxtsx.This is my stripped down example:
import { drizzle } from "drizzle-orm/node-postgres";
import {
InferModel,
pgTable,
serial,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { Pool } from "pg";
export const domains = pgTable("domains", {
id: serial("id").primaryKey(),
domain: text("domain").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
export type Domain = InferModel<typeof domains>;
export type NewDomain = InferModel<typeof domains, "insert">;
const pool = new Pool({
connectionString: "postgres://robin@localhost/ts-drizzle",
});
const db = drizzle(pool);
async function main() {
// Insert
const d: NewDomain = {
domain: "foo.com",
};
const inserted = await db.insert(domains).values(d).returning();
console.log(inserted);
}
main();import { drizzle } from "drizzle-orm/node-postgres";
import {
InferModel,
pgTable,
serial,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { Pool } from "pg";
export const domains = pgTable("domains", {
id: serial("id").primaryKey(),
domain: text("domain").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
export type Domain = InferModel<typeof domains>;
export type NewDomain = InferModel<typeof domains, "insert">;
const pool = new Pool({
connectionString: "postgres://robin@localhost/ts-drizzle",
});
const db = drizzle(pool);
async function main() {
// Insert
const d: NewDomain = {
domain: "foo.com",
};
const inserted = await db.insert(domains).values(d).returning();
console.log(inserted);
}
main();This is my
tsconfig.jsontsconfig.json:{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"strict": true
}
}{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"esModuleInterop": true,
"strict": true
}
}Running it:
$ npx tsx main.ts
SyntaxError: The requested module 'pg' does not provide an export named 'Pool'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)$ npx tsx main.ts
SyntaxError: The requested module 'pg' does not provide an export named 'Pool'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)