Turborepo - no type safety when using drizzle in other modules

Hi all, I am setting up a monorepo with turborepo where I have an API under apps/api and a database module under packages/db. I am losing type safety when importing the db instance in another package. I export all of my tables and the drizzle instance like so below:
// packages/db/src/index.ts
import "@dotenvx/dotenvx";
import { drizzle } from "drizzle-orm/libsql";
import * as schema from "./schemas"; // barrel file to export all schemas and types

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL not set");
}

export const db = drizzle({
connection: {
url: process.env.DATABASE_URL,
authToken: process.env.AUTH_TOKEN,
},
schema,
});
export * from "drizzle-orm";
export * from "./schemas";
// packages/db/src/index.ts
import "@dotenvx/dotenvx";
import { drizzle } from "drizzle-orm/libsql";
import * as schema from "./schemas"; // barrel file to export all schemas and types

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL not set");
}

export const db = drizzle({
connection: {
url: process.env.DATABASE_URL,
authToken: process.env.AUTH_TOKEN,
},
schema,
});
export * from "drizzle-orm";
export * from "./schemas";
I am not sure if this is a problem with my tsconfig for both of these modules or how I am exporting packages. I attached screenshots of what my IDE displays when I hover over users and what the returned value should be. Any help would be appreciated, thank you 🙏
No description
No description
1 Reply
steezus
steezusOP3mo ago
so it was a tsconfig issue, if anyone stumbles across this in the future, this is the tsconfig I have setup
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ES2022",
"lib": ["ES2022"],
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"incremental": true,
"disableSourceOfProjectReferenceRedirect": true,
"tsBuildInfoFile": "${configDir}/.cache/tsbuildinfo.json",
"strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
"module": "Preserve",
"moduleResolution": "Bundler",
"noEmit": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"noEmit": false,
"outDir": "${configDir}/dist"
},
"exclude": ["node_modules", "build", "dist"]
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ES2022",
"lib": ["ES2022"],
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"incremental": true,
"disableSourceOfProjectReferenceRedirect": true,
"tsBuildInfoFile": "${configDir}/.cache/tsbuildinfo.json",
"strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
"module": "Preserve",
"moduleResolution": "Bundler",
"noEmit": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"noEmit": false,
"outDir": "${configDir}/dist"
},
"exclude": ["node_modules", "build", "dist"]
}

Did you find this page helpful?