Doesn't drizzle-kit generate:pg work yet when schema imports from esm package?

> drizzle-kit generate:pg --out src/db/migrations --schema src/db/schemas

drizzle-kit: v0.17.0
drizzle-orm: v0.23.1

{ out: 'src/db/migrations', schema: [ 'src/db/schemas' ] }
/home/karmo/Code/project1/packages/database-drizzle-orm/dist/esm/index.mjs:2
import { drizzle } from "drizzle-orm/node-postgres";
^^^^^^

SyntaxError: Cannot use import statement outside a module
> drizzle-kit generate:pg --out src/db/migrations --schema src/db/schemas

drizzle-kit: v0.17.0
drizzle-orm: v0.23.1

{ out: 'src/db/migrations', schema: [ 'src/db/schemas' ] }
/home/karmo/Code/project1/packages/database-drizzle-orm/dist/esm/index.mjs:2
import { drizzle } from "drizzle-orm/node-postgres";
^^^^^^

SyntaxError: Cannot use import statement outside a module
Building from TS to ESM JS works fine.
9 Replies
Andrii Sherman
Do you have anything else in file with schemas except of tables/enums?
karmux
karmuxOP2y ago
Yes but removing extras (Error class and InferModels) does not fix it. I'm using own esm package to reexport drizzle-orm exports to have single drizzle-orm defined in the project. I run into some weird TS errors when I installed drizzle-orm separately to every app.
import {
bigserial,
boolean,
createInsertSchema,
createTimestampColumns,
createTimestampIndices,
decimal,
// InferModel,
pgTable,
text,
uniqueIndex,
} from '@project1/database-drizzle-orm';
import {
bigserial,
boolean,
createInsertSchema,
createTimestampColumns,
createTimestampIndices,
decimal,
// InferModel,
pgTable,
text,
uniqueIndex,
} from '@project1/database-drizzle-orm';
@project1/database-drizzle-orm is an esm package reexporting drizzle stuff and some helper functions. At least would be great to be able to import
createTimestampColumns,
createTimestampIndices,
createTimestampColumns,
createTimestampIndices,
helper functions from esm helper package into schema file.
Andrii Sherman
Do you have multiple drizzle-orm packages installed in 1 project? Also in your error I see import { drizzle } from "drizzle-orm/node-postgres"; error, but can't see it here
import {
bigserial,
boolean,
createInsertSchema,
createTimestampColumns,
createTimestampIndices,
decimal,
// InferModel,
pgTable,
text,
uniqueIndex,
} from '@project1/database-drizzle-orm';
import {
bigserial,
boolean,
createInsertSchema,
createTimestampColumns,
createTimestampIndices,
decimal,
// InferModel,
pgTable,
text,
uniqueIndex,
} from '@project1/database-drizzle-orm';
If you could provide small project example with structure you are using - I can take a look and help you or find the reason why drizzle-kit is not working in this case You can do really simple small example. Important is to have same structure you have in your project
karmux
karmuxOP2y ago
Provided minimum reproducible example under comments of https://github.com/drizzle-team/drizzle-kit-mirror/issues/21
GitHub
Issue when generating sql using zod for environment variable valida...
When using npx drizzle-kit generate:mysql with other source for env variables, an error is thrown. npx drizzle-kit generate:mysql drizzle-kit: v0.17.0 drizzle-orm: v0.22.0-88c1ad3 /home/stneto/apps...
Andrii Sherman
Thanks a lot! Will test it tomorrow and ping you back here Did reproduce it working on it
karmux
karmuxOP2y ago
Hi. Any update on this? Can I help somehow? This issue is the last issue keeping us using TypeORM.
OssuBoy
OssuBoy2y ago
We have also same problem related to that when we want to use ESM packages what we have made. Did you find something? @Andrew Sherman
Andrii Sherman
could you please share drizzle-orm and drizzle-kit versions you are using?
OssuBoy
OssuBoy2y ago
@Andrew Sherman Project example is here https://github.com/drizzle-team/drizzle-kit-mirror/issues/21 drizzle-orm: "^0.23.1" and no drizzle-kit
GitHub
Issue when generating sql using zod for environment variable valida...
When using npx drizzle-kit generate:mysql with other source for env variables, an error is thrown. npx drizzle-kit generate:mysql drizzle-kit: v0.17.0 drizzle-orm: v0.22.0-88c1ad3 /home/stneto/apps...
Want results from more Discord servers?
Add your server