drizzle-orm: [BUG]: Many TypeScript Compile Errors (drizzle-orm/neon-http ; Postgres)

What version of drizzle-orm are you using?

^0.28.6

What version of drizzle-kit are you using?

^0.19.13

Describe the Bug

During the build step for Typescript, I run into the same “10 errors in 9 files” within the drizzle-orm Node modules package. Reproduced in 3 different projects, one of new was fresh, following the instructions step-by-step for Neon integration over http, as Firebase Cloud Functions do not support Web Sockets (to my knowledge; I could be wrong.)

Step 1:

yarn add drizzle-orm @neondatabase/serverless
yarn add -D drizzle-kit

Step 2: Ensure your env contains the string you need and is being read, then -

import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
 
neonConfig.fetchConnectionCache = true;
 
const sql = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);

Step 3:

yarn tsc

Build Errors (Same In all Projects Tested):

$ yarn build
yarn run v1.22.19
$ tsc
node_modules/drizzle-orm/mysql-core/db.d.ts:1:38 - error TS2307: Cannot find module 'mysql2/promise' or its corresponding type declarations.

1 import type { ResultSetHeader } from 'mysql2/promise';
                                       ~~~~~~~~~~~~~~~~

node_modules/drizzle-orm/mysql-core/query-builders/delete.d.ts:15:22 - error TS2420: Class 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' incorrectly implements interface 'SQLWrapper'.
  Property 'getSQL' is missing in type 'MySqlDelete<TTable, TQueryResult, TPreparedQueryHKT>' but required in type 'SQLWrapper'.

15 export declare class MySqlDelete<TTable extends MySqlTable, TQueryResult extends QueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase> extends QueryPromise<QueryResultKind<TQueryResult, never>> implements SQLWrapper {
                        ~~~~~~~~~~~

  node_modules/drizzle-orm/sql/index.d.ts:47:5
    47     getSQL(): SQL;
           ~~~~~~~~~~~~~~
    'getSQL' is declared here.

node_modules/drizzle-orm/mysql-core/query-builders/select.d.ts:74:22 - error TS2515: Non-abstract class 'MySqlSelect<TTableName, TSelection, TSelectMode, TPreparedQueryHKT, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.

74 export declare class MySqlSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TPreparedQueryHKT extends PreparedQueryHKTBase, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends MySqlSelectQueryBuilder<MySqlSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
                        ~~~~~~~~~~~

node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:17:22 - error TS2420: Class 'PgDelete<TTable, TQueryResult, TReturning>' incorrectly implements interface 'SQLWrapper'.
  Property 'getSQL' is missing in type 'PgDelete<TTable, TQueryResult, TReturning>' but required in type 'SQLWrapper'.

17 export declare class PgDelete<TTable extends PgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
                        ~~~~~~~~

  node_modules/drizzle-orm/sql/index.d.ts:47:5
    47     getSQL(): SQL;
           ~~~~~~~~~~~~~~
    'getSQL' is declared here.

node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:193:22 - error TS2515: Non-abstract class 'PgSelect<TTableName, TSelection, TSelectMode, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap>'.

193 export declare class PgSelect<TTableName extends string | undefined, TSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends PgSelectQueryBuilder<PgSelectHKT, TTableName, TSelection, TSelectMode, TNullabilityMap> {
                         ~~~~~~~~

node_modules/drizzle-orm/sqlite-core/columns/blob.d.ts:1:23 - error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.

1 /// <reference types="node" resolution-mode="require"/>
                        ~~~~

node_modules/drizzle-orm/sqlite-core/columns/blob.d.ts:2:23 - error TS2688: Cannot find type definition file for 'bun-types'.

2 /// <reference types="bun-types" />
                        ~~~~~~~~~

node_modules/drizzle-orm/sqlite-core/query-builders/query.d.ts:24:22 - error TS2420: Class 'SQLiteRelationalQuery<TType, TResult>' incorrectly implements interface 'SQLWrapper'.
  Property 'getSQL' is missing in type 'SQLiteRelationalQuery<TType, TResult>' but required in type 'SQLWrapper'.

24 export declare class SQLiteRelationalQuery<TType extends 'sync' | 'async', TResult> extends QueryPromise<TResult> implements SQLWrapper {
                        ~~~~~~~~~~~~~~~~~~~~~

  node_modules/drizzle-orm/sql/index.d.ts:47:5
    47     getSQL(): SQL;
           ~~~~~~~~~~~~~~
    'getSQL' is declared here.

node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.ts:8:22 - error TS2420: Class 'SQLiteRaw<TRunResult>' incorrectly implements interface 'SQLWrapper'.
  Property 'getSQL' is missing in type 'SQLiteRaw<TRunResult>' but required in type 'SQLWrapper'.

8 export declare class SQLiteRaw<TRunResult> extends QueryPromise<TRunResult> implements SQLWrapper {
                       ~~~~~~~~~

  node_modules/drizzle-orm/sql/index.d.ts:47:5
    47     getSQL(): SQL;
           ~~~~~~~~~~~~~~
    'getSQL' is declared here.

node_modules/drizzle-orm/sqlite-core/query-builders/select.d.ts:74:22 - error TS2515: Non-abstract class 'SQLiteSelect<TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap>' does not implement inherited abstract member 'getSQL' from class 'SQLiteSelectQueryBuilder<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap>'.

74 export declare class SQLiteSelect<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}> extends SQLiteSelectQueryBuilder<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap> {
                        ~~~~~~~~~~~~


Found 10 errors in 9 files.

Errors  Files
     1  node_modules/drizzle-orm/mysql-core/db.d.ts:1
     1  node_modules/drizzle-orm/mysql-core/query-builders/delete.d.ts:15
     1  node_modules/drizzle-orm/mysql-core/query-builders/select.d.ts:74
     1  node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:17
     1  node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:193
     2  node_modules/drizzle-orm/sqlite-core/columns/blob.d.ts:1
     1  node_modules/drizzle-orm/sqlite-core/query-builders/query.d.ts:24
     1  node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.ts:8
     1  node_modules/drizzle-orm/sqlite-core/query-builders/select.d.ts:74
error Command failed with exit code 2.

Expected behavior

Expect TypeScript to be able to build. Confirmed errors exist in individual node_module files noted in build process as well

Environment & setup

Server Platform: Firebase Cloud Functions Node Version: 18 Database Type: Neon.tech PostgreSQL Connection Type: http, ssl TypeScript Version: “^4.9.0” Editor: VSCode

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 15
  • Comments: 22

Commits related to this issue

Most upvoted comments

I was able to overcome this by setting "skipLibCheck": true, in tsconfig.json

Ditto here for PostgresJS and PG versions. Production blocker for me as app must compile correctly before deployment.

Yeah although it’s not ideal it’s not ignoring typescript altogether. You still get types being enforced for the definitions that exist.

I think the main issue here though is the library is currently broken for use with postgres for a number of versions and there doesn’t seem to be any communication from the drizzle team. It doesn’t feel that this should be too hard to fix but I haven’t had time to dig into it myself.

Having this issue trying to use sqlite also for the record

This is a known issue with drizzle. Due to the fact that drizzle supports several drivers, we need to add peer dependencies for those drivers, even if you don’t use them. One solution is to just install them (which is totally not necessary), and the best solution is what was already suggested "skipLibCheck": true. Please keep in mind, this is not a hack, I’ve seen prolific typescript devs/creators suggest and recommend adding this to tsconfig.

Edit: source

I’ve actually replicated this in similar environments with the PostgresJS and PG versions of drizzle as well (instead of neon-http). Some of the type errors differ, but they all have extensive type errors.

I would disagree about the skipLibCheck comment. It would still be considered a hack not a solution. Despite what we see in other devs: prolific or not. If the library has dependencies that it relies upon you either should modularize your code correctly(preferred way) & install dependencies or mark dependencies as a peerDependency so that a consumer knows what to do.

I’m hitting this with the quick start (https://orm.drizzle.team/kit-docs/quick), using postgresJS. Furthermore, running the resulting js file errors as well.


Error from pnpm tsc src/index.ts

...
Found 23 errors in 12 files.

Errors  Files
     2  src/index.ts:3
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/mysql-core/db.d.ts:1
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/mysql-core/query-builders/delete.d.ts:30
     7  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/mysql-core/query-builders/select.d.ts:66
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/mysql-core/query-builders/select.types.d.ts:130
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:32
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:205
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/sqlite-core/columns/blob.d.ts:2
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/sqlite-core/query-builders/query.d.ts:25
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/sqlite-core/query-builders/raw.d.ts:11
     5  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/sqlite-core/query-builders/select.d.ts:69
     1  ../../node_modules/.pnpm/drizzle-orm@0.29.0_postgres@3.4.3/node_modules/drizzle-orm/sqlite-core/query-builders/select.types.d.ts:122

error from node src/index.js

var sql = (0, postgres_1.default)(connectionString, { max: 1 });
                                 ^

TypeError: (0 , postgres_1.default) is not a function
    at Object.<anonymous> (/home/shot/Develop/sky-hustlers/v2/heavens-jigsaw/apps/db/src/index.js:7:34)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v21.2.0

I experienced the same problem with better-sqlite3 client and docker compose build. I don`t understand why I need this with sqlite:

node_modules/.pnpm/drizzle-orm@0.28.6_@types+better-sqlite3@7.6.6_better-sqlite3@9.0.0/node_modules/drizzle-orm/mysql-core/db.d.ts:1:38 - error TS2307: Cannot find module 'mysql2/promise' or its corresponding type declarations.

1 import type { ResultSetHeader } from 'mysql2/promise';
                                       ~~~~~~~~~~~~~~~~

It seems crazy to hit this right out of the box and to see that it’s been an open issue for month, or actually since July…

https://github.com/drizzle-team/drizzle-orm/issues/879

Could this only be an issue for recent versions of typescript and/or module/resolution settings?