drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
291 stars 17 forks source link

drizzle-kit: ""import.meta" is not available" error #437

Open PurpleTape opened 3 months ago

PurpleTape commented 3 months ago

I am using drizzle-kit in my project with the Vite development server. At the same time, the schema files are located in different directories of my project, inside the src folder.

When I try to execute the drizzle-kit pull or drizzle-kit generate command, an error occurs:

> drizzle-kit push

drizzle-kit: v0.21.2
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file '/my-app-path/drizzle.config.ts'
Using 'pg' driver for database querying
{
  column: 54,
  file: '/my-app-path/src/utils/libs/i18n/i18n.ts',
  length: 11,
  line: 22,
  lineText: "const modules: Record<string, { default: unknown }> = import.meta.glob('/translations/*.json', {",
  namespace: '',
  suggestion: ''
}
"import.meta" is not available with the "cjs" output format and will be empty
TypeError: import_meta.glob is not a function
    at Object.<anonymous> (/my-app-path/src/utils/libs/i18n/i18n.ts:22:67)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._compile (/my-app-path/node_modules/drizzle-kit/bin.cjs:11751:31)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Object.newLoader [as .ts] (/my-app-path/node_modules/drizzle-kit/bin.cjs:11755:13)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/my-app-path/src/utils/libs/i18n/index.ts:2:15)

This is most likely due to the fact that when it try to run schema files, files containing Vite-specific code are run too.

Please specify is there a way to fix this?

Thanks!

danielo515 commented 1 month ago

I am facing exactly this same problem. I would love to know how to fix it, since I want to use drizzle with astro

eKulshan commented 1 week ago

Facing the same issue Pure fastify based backend api, so I'm not sure that this is related to vite I have type: 'module' in package.json and using import.meta.dirname for building relative path to my .env file