Type Declaration with TypeScript in Monorepo failes

I am trying to setup a monorepo with moon and pnpm, where shema lives in an additional package and is imported by other apps. Is there any monorepo example? Currently I get following error:
../db/src/schema/products.ts(4,14): error TS2742: The inferred type of 'products' cannot be named without a reference to '../../node_modules/drizzle-orm/db.d-a6fe1b19.js'. This is likely not portable. A type annotation is necessary.
../db/src/schema/products.ts(4,14): error TS2742: The inferred type of 'products' cannot be named without a reference to '../../node_modules/drizzle-orm/db.d-a6fe1b19.js'. This is likely not portable. A type annotation is necessary.
There is an GitHub Issue already, can anyone help with workarounds or fixes, explanations? https://github.com/drizzle-team/drizzle-orm/issues/656
GitHub
[BUG]: "composite" true and Yarn workspace prevents pgTable fro...
What version of drizzle-orm are you using? 0.26.1 What version of drizzle-kit are you using? 0.18.1 Describe the Bug TL;DR TypeScript can't compile simple schema.ts file with users example tabl...
3 Replies
Maston
Maston2y ago
if you dont compile your db package and you have "main": "src/index.ts" in your package.json, you can try "declaration": false in your tsconfig, this may have downsides though they also don't reccomend you install drizzle in more than one package in a monorepo, personally i just have a singular package which has an entrypoint that looks like this
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres, { type Sql } from 'postgres';

import { schema } from './schema';
import { type Database, type DatabaseOptions } from './types';

export const createDatabase = (options: DatabaseOptions): { db: Database; sql: Sql } => {
const sql = postgres(options);
const db = drizzle(sql, { ...options, schema });

return { db, sql };
};

export * from './types';
export * from './schema';
export * from './helpers';
export * from 'drizzle-orm/postgres-js';
export * from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres, { type Sql } from 'postgres';

import { schema } from './schema';
import { type Database, type DatabaseOptions } from './types';

export const createDatabase = (options: DatabaseOptions): { db: Database; sql: Sql } => {
const sql = postgres(options);
const db = drizzle(sql, { ...options, schema });

return { db, sql };
};

export * from './types';
export * from './schema';
export * from './helpers';
export * from 'drizzle-orm/postgres-js';
export * from 'drizzle-orm';
Maston
Maston2y ago
GitHub
"The inferred type of X cannot be named without a reference to Y" (...
Bug Report 🔎 Search Terms TS2742 cannot be named without a reference 🕗 Version & Regression Information Problems occurs with 4.5.x and 4.6.x and most likely earlier versions (I've tried a f...
alex (he/him)
alex (he/him)OP2y ago
Thanks, but while the linked comment seems to have workarounds, which do not work in this case. Also disabling declaration is not possible because of the monorepo structure and composite: true. Re-Exporting the package is a good tipp, but sadly helps not with the TS error.
Want results from more Discord servers?
Add your server