drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.01k stars 606 forks source link

[BUG]: `import_pg_core.isPgView` is not a function #3131

Closed mmikhan closed 1 week ago

mmikhan commented 1 week ago

What version of drizzle-orm are you using?

0.34.1

What version of drizzle-kit are you using?

0.26.0

Describe the Bug

Running pnpm drizzle-kit generate shows the following error in the drizzle-kit v0.26.0 that was released recently but downgrading to v0.25.0 works fine.

No config path provided, using default 'drizzle.config.ts'
Reading config file '/ispgviewisnotafunction/drizzle.config.ts'
TypeError: (0 , import_pg_core.isPgView) is not a function
    at /ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:18878:41
    at Array.forEach (<anonymous>)
    at prepareFromExports2 (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:18867:16)
    at prepareFromPgImports (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:18901:26)
    at async serializePg (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:21066:70)
    at async preparePgMigrationSnapshot (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:21204:26)
    at async prepareAndMigratePg (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:31886:48)
    at async Object.handler (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:87076:7)
    at async run (/ispgviewisnotafunction/node_modules/.pnpm/drizzle-kit@0.26.0/node_modules/drizzle-kit/bin.cjs:85613:7)

Expected behavior

pnpm drizzle-kit generate generates the schema

Environment & setup

Reproducible in a fresh Next.js app. For your convenience, I have created one for you here: https://github.com/mmikhan/ispgviewisnotafunction. Clone the repo and run the pnpm drizzle-kit generate command

nosliwsirhc commented 1 week ago

This is happening for me as well. "drizzle-orm": "^0.34.1", "pg": "^8.13.0", "drizzle-kit": "^0.26.0"

My drizzle.config.ts file looks like this:

`import * as dotenv from "dotenv"; import { defineConfig } from "drizzle-kit";

// Load environment variables dotenv.config();

// Determine the current environment const isDevelopment = process.env.NODE_ENV !== "production";

// Define required environment variables const requiredEnvVars = [ "DATABASE_HOST", "DATABASE_PORT", "DATABASE_USERNAME", "DATABASE_PASSWORD", isDevelopment ? "DATABASE_DB_DEV" : "DATABASE_DB_PROD", ];

// Check if environment variables are set and create a typed object const envVars = requiredEnvVars.reduce((acc, key) => { const value = process.env[key]; if (value === undefined) { throw new Error(Missing required environment variable: ${key}); } return { ...acc, [key]: value }; }, {} as Record<string, string>);

// Parse the port to ensure it's a number const port = parseInt(envVars.DATABASE_PORT, 10); if (isNaN(port)) { throw new Error("DATABASE_PORT must be a valid number"); }

export default defineConfig({ schema: "./src/**/schema.ts", out: "./src/app/core/drizzle/migrations", dialect: "postgresql", dbCredentials: { host: envVars.DATABASE_HOST, port: port, database: isDevelopment ? envVars.DATABASE_DB_DEV : envVars.DATABASE_DB_PROD, user: envVars.DATABASE_USERNAME, password: envVars.DATABASE_PASSWORD, }, verbose: isDevelopment, strict: true, });`

AndriiSherman commented 1 week ago

please install both orm and kit packages to the latest version