drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Please install latest version of "drizzle-orm" - with latest Drizzle version

Open TobiTRy opened this issue 1 year ago • 2 comments

What version of drizzle-orm are you using?

0.32.1

What version of drizzle-kit are you using?

0.23.0

Describe the Bug

Steps to Reproduce:

  1. Created a new package within my npm workspace dedicated to database handling.
  2. Set up a new Drizzle configuration, ensuring I installed the latest versions of both drizzle-orm and drizzle-kit.
  3. Ran the command npx drizzle-kit generate:pg.

Actual Behavior: I consistently receive the following error message:

drizzle-kit: v0.23.0

Please install latest version of drizzle-orm

Additional Information:

  • npm workspace structure:
"workspaces": [
   "apps/*",
   "packages/*"
 ],
  • Operating System: Windows 10
  • Node.js version: 20.10.0

Possible Workarounds:

  • Tried updating all drizzle-orm dependencies in my workspace to the latest version, but the issue persists.

Notes:

Currently i downgraded to:

    "drizzle-kit": "^0.20.17",
    "drizzle-orm": "^0.30.10",

But the issue on this versions is, drizzle studio does not work... ist very frustrating

This issue seems similar to the one reported in [#406](https://github.com/drizzle-team/drizzle-kit-mirror/issues/406), but the solution there did not resolve my problem. It could be a dependency resolution issue within the npm workspace.

Expected behavior

Drizzle should work without errors.

Environment & setup

No response

TobiTRy avatar Jul 27 '24 09:07 TobiTRy

I think this is the same issue as I have: https://github.com/pnpm/pnpm/issues/8163

benjick avatar Jul 27 '24 21:07 benjick

I fixed the issue by installing the package in the root folder of my monorepo. I'm still looking for a solution to move it back into the individual package.

TobiTRy avatar Aug 03 '24 19:08 TobiTRy

In my case, I had drizzle-kit installed globally and when I tried to run migrate or generate it threw the same error message. The fix was to run drizzle-kit from the local dependencies (via scripts).

iiAbady avatar Aug 25 '24 04:08 iiAbady

I use pnpm exec drizzle-kit generate to get by this for now.

timotew avatar Aug 31 '24 08:08 timotew

I use pnpm exec drizzle-kit generate to get by this for now.

This command worked for me. Thanks!

Himashana avatar Nov 29 '24 10:11 Himashana

When using PNPM, just use pnpm drizzle-kit generate

mmikhan avatar Dec 05 '24 10:12 mmikhan

When using PNPM, just use pnpm drizzle-kit generate

not work for me

ishowman avatar Dec 07 '24 11:12 ishowman

Add

"db:generate": "drizzle-kit generate",
    "db:migrate": "drizzle-kit migrate",

and run pnpm run db:generate. perfect

harveyjing avatar Dec 11 '24 16:12 harveyjing

@AndriiSherman what's the fix?

apps/nextjs/package.json:

  "scripts": {
    "drizzle-kit-version": "drizzle-kit --version"
  },
  "dependencies": {
    "drizzle-kit": "0.30.1",
    "drizzle-orm": "0.38.2",
    "drizzle-zod": "0.6.0"
  },
pnpm drizzle-kit-version

> @nextgen/[email protected] drizzle-kit-version /Users/max/dev/merlin/apps/nextjs
> drizzle-kit --version

drizzle-kit: v0.30.1
drizzle-orm: v0.29.3 

benjick avatar Dec 17 '24 19:12 benjick

I'm also wondering @AndriiSherman. Issue remains on my side.

bjornlll avatar Dec 28 '24 04:12 bjornlll

I'm having the same issue running npx drizzle-kit push and via scripts in the package.json. I'm using turbo to manage a monorepo. I had to install drizzle-orm at root level :(

raffaele-filiberti avatar Jan 16 '25 18:01 raffaele-filiberti

I had the same issue with pnpm monorepo. adding public-hoist-pattern[]=drizzle-orm into .npmrc resolved the issue. apparently the import(drizzle-orm) can't properly resolve the drizzle-orm location, not sure who is responsible for this whether pnpm or drizzle-kit :)

zemd avatar Jan 26 '25 19:01 zemd

Same issue. I am using a simple npm workspace. I fixed it by adding in the root package.json (which is pretty messy..)

  "dependencies": {
    "drizzle-orm": "^0.36.1"
  },

Its an open source Project: https://github.com/alan345/Fullstack-SaaS-Boilerplate

alan345 avatar Jan 29 '25 22:01 alan345

https://github.com/drizzle-team/drizzle-orm/issues/2614 https://github.com/drizzle-team/drizzle-orm/issues/2699 https://github.com/drizzle-team/drizzle-orm/issues/3248 https://github.com/drizzle-team/drizzle-orm/issues/3578 https://github.com/drizzle-team/drizzle-orm/issues/3934

All these are somehow related: when a user is setup with npm workspaces (monorepo), sometimes drizzle-kit is hoisted and drizzle-orm is not. Depending on the versions, sometimes both get hoisted and it works. Currently, I have these two versions working OK (as both get hoisted):

    "drizzle-kit": "0.30.4",
    "drizzle-orm": "0.39.0",

If i was to update drizzle-orm to 0.39.0, it would no longer hoist it and drizzle-kit would come up with the dreaded: Please install latest version of drizzle-orm.

The trigger is this block which throws because await import('drizzle-orm/version') doesn't find drizzle-orm.

$ node -v
v22.13.1
$ npm -v
10.9.2

akmoulai avatar Feb 01 '25 16:02 akmoulai

public-hoist-pattern[]=drizzle-orm

this sadly doesn't work when you actually have multiple versions of the library. The only solution I've gotten to work so far is node-linker=hoisted, but then you lose the symlinking goodies of using pnpm

hoisted - a flat node_modules without symlinks is created. Same as the node_modules created by npm or Yarn Classic.

benjick avatar Feb 01 '25 18:02 benjick

this sadly doesn't work when you actually have multiple versions of the library.

why would you want to use multiple different versions within the same monorepo? you also can use catalog: deps if you want to sync them

zemd avatar Feb 01 '25 19:02 zemd

this sadly doesn't work when you actually have multiple versions of the library.

why would you want to use multiple different versions within the same monorepo? you also can use catalog: deps if you want to sync them

In my case I'm using another dependency which lags behind on which drizzle version they are using. So two apps using different versions

benjick avatar Feb 01 '25 20:02 benjick

A workaround that worked for me using good old plain npm with turborepo is to npm install --force drizzle-kit drizzle-orm in the root of your monorepo, then manually remove the entries again from the root package.json, run npm install again. And now you'll be able to run the drizzle-kit commands in your sub package.

wouterds avatar Feb 15 '25 10:02 wouterds

This also worked here! Thanks!

A workaround that worked for me using good old plain npm with turborepo is to npm install --force drizzle-kit drizzle-orm in the root of your monorepo, then manually remove the entries again from the root package.json, run npm install again. And now you'll be able to run the drizzle-kit commands in your sub package.

juliano340 avatar Feb 16 '25 03:02 juliano340

Why was this closed? This is still an issue

jczstudios avatar Mar 04 '25 19:03 jczstudios

Still an issue. Very frustrating. I just run npx drizzle-kit generate each time.

i-am-rad avatar Mar 09 '25 15:03 i-am-rad

If you're working with pnpm workspaces/turborepo and facing this issue, a helper script at the root may help:

Add this script in the database package:

// packages/database/package.json 

{
"name": "@repo/database",
"dependencies": {
	"drizzle-kit": "~0.30.5",
	"drizzle-orm": "~0.40.1",
	"pg": "~8.14.0",
},
"scripts": {
		"db": "drizzle-kit"
	},
}

and in the root package.json add:


{
"name": "my-monorepo",
"scripts": {
		"db": "pnpm --filter @repo/database run db"
	},
}

Then you can run pnpm db migrate from the root.

apetta avatar Mar 18 '25 23:03 apetta

Still having this issue as well within a pnpm monorepo, drizzle-kit and drizzle-orm are installed only within a single service, not at the root. Issue is on one devs machine, and not another.

The error is slightly different, Please install required packages: 'drizzle-orm' so it seems to not be able to find it at all.

theoephraim avatar Mar 25 '25 23:03 theoephraim

#2614 #2699 #3248 #3578 #3934

All these are somehow related: when a user is setup with npm workspaces (monorepo), sometimes drizzle-kit is hoisted and drizzle-orm is not. Depending on the versions, sometimes both get hoisted and it works. Currently, I have these two versions working OK (as both get hoisted):

    "drizzle-kit": "0.30.4",
    "drizzle-orm": "0.39.0",

If i was to update drizzle-orm to 0.39.0, it would no longer hoist it and drizzle-kit would come up with the dreaded: Please install latest version of drizzle-orm.

The trigger is this block which throws because await import('drizzle-orm/version') doesn't find drizzle-orm.

$ node -v
v22.13.1
$ npm -v
10.9.2

so far this work best imo

azuddin avatar Apr 07 '25 13:04 azuddin

+1, still an issue, pnpm, turborepo

maxktz avatar Apr 17 '25 15:04 maxktz

+1, still an issue

mad-coder-365 avatar May 26 '25 15:05 mad-coder-365

+!, still an issue, pnpm, turborepo

0xPT avatar Jun 04 '25 23:06 0xPT

+1, still an issue, npm, turborepo

grantborgognoni avatar Jun 23 '25 17:06 grantborgognoni

+1, have this issue with yarn, turbo repo

snoolord avatar Jun 28 '25 16:06 snoolord

As far as I can tell, the issue here is a confluence of a few things:

  1. the published drizzle-kit package's package.json declares the drizzle-orm dependency with a workspace link, as if it were still in the project's source monorepo: "drizzle-orm": "workspace:./drizzle-orm/dist",
  2. NPM will hoist drizzle-kit but not drizzle-orm in workspaces with a package that depends on drizzle-kit, drizzle-orm, and another that has a drizzle-orm peer dependency such as @effect/sql-drizzle

To illustrate a bit: /root/package.json (workspace package.json, no drizzle deps) /root/backend/package.json (drizzle-kit, drizzle-orm, @effect/sql-drizzle)

NPM will put @effect/sql-drizzle and drizzle-orm into /root/backend/node_modules to ensure peer dependency resolution, but will hoist drizzle-kit because it is free of peer dependencies and, I believe, because it has that "workspace:./drizzle-orm/dist" drizzle-orm dev dependency so there's no clear link (in NPM's algorithm) to the non-hoisted drizzle-orm.

Then when I run npx drizzle-kit ..., or an npm run script that uses drizzle-kit, in /root/backend I get an error about being unable to find drizzle-orm because calling require('drizzle-orm') in /root/node_modules won't look for it in /root/backend/node_modules.

If I swap from using NPM with workspaces to PNPM with workspaces, both drizzle-kit and drizzle-orm end up accessible in /root/backend/node_modules and so then when I run pnpm exec drizzle-kit ... in /root/backend it works because pnpm does not hoist drizzle-kit up and both packages are in /root/backend/node_modules.

I noticed that this project itself is using pnpm so I'm guessing the authors are also using pnpm.

IMO this is a bug and should be reopened. I shouldn't have to use the same package manager.

jeremiahrhall avatar Jul 17 '25 18:07 jeremiahrhall