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
21.47k stars 486 forks source link

[BUG]: `drizzle-kit` generate fails to resolve imports #2455

Open demosjarco opened 3 weeks ago

demosjarco commented 3 weeks ago

What version of drizzle-orm are you using?

0.31.1

What version of drizzle-kit are you using?

0.22.2

Describe the Bug

Importing another table from another drizzle schema file (both are sqliteTable()) using

import { users as dataspaceUsers } from '../dataspace/index.js';

fails unless I remove the /index.js like:

import { users as dataspaceUsers } from '../dataspace';

which then works as expected when running drizzle-kit generate. But this breaks the schema file when being imported to be used by drizzle-orm normally at runtime:

Uncaught Error Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '<redacted>\dist\schemas\dataspace' is not supported resolving ES modules imported from <redacted>\dist\schemas\tenant\index.js

which is fixable by keeping the full path:

import { users as dataspaceUsers } from '../dataspace/index.js';

Expected behavior

I use the

import { users as dataspaceUsers } from '../dataspace/index.js';

and the import resolves as expected both during drizzle-kit and drizzle-orm runtime

Environment & setup

drizzle-kit is ran using exec() inside a node.js script that is ran in GitHub actions as part of overall project ci/cd to do automated migrations. drizzle-orm using that schema is at regular runtime being used either in node.js environment or cloudflare workers environment.

axe312ger commented 3 weeks ago

I just had to migrate the whole project to use .js in the imports so I can use an ESM-only package... https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

And now my drizzle generate broke 😿