How to share drizzle schemas in a npm package?

Hi there, how could I share some table schemas from a npm package? I've tried to export the schema.ts in package.json like
"exports": {
"./schema": {
"default": "./src/schema.ts"
}
}
"exports": {
"./schema": {
"default": "./src/schema.ts"
}
}
and add it in the consuming app to the schema array of drizzle.config.ts like
export default defineConfig({
dialect: 'postgresql',
schema: [
'./src/db/*/schema.ts',
'./src/db/*/views.ts',
'my-package/schema',
]
...
export default defineConfig({
dialect: 'postgresql',
schema: [
'./src/db/*/schema.ts',
'./src/db/*/views.ts',
'my-package/schema',
]
...
but drizzle-kit seems to simply ignore this without any error
3 Replies
djoh the III
djoh the III3w ago
have you tried re-exporting the packaged schema from a file within your project and then referencing that file instead?
JustWayne
JustWayne3w ago
I bet in your drizzle config you would have to set the path to ./node_modules/my-package/src/schema.ts
djoh the III
djoh the III3w ago
or that yeah

Did you find this page helpful?