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
24.54k stars 643 forks source link

`drizzle-kit@0.21.0` uses `@libsql/client`, not installed in the workspace #3429

Open hyunbinseo opened 6 months ago

hyunbinseo commented 6 months ago

According to the v0.21.0 release note:

For sqlite dialect, Drizzle will:

  • Check if the @libsql/client driver is installed and use it.
  • If not, try to find better-sqlite3 and use it.
  • If nothing is found, an error will be thrown

There seems to be a resolution error with the pnpm package manager.

Even in a workspace where @libsql/client is not installed as a (dev) dependency,

pnpm why better-sqlite3

# dependencies:
# better-sqlite3 9.6.0
# drizzle-orm 0.30.10
# └── better-sqlite3 9.6.0 peer

pnpm why @libsql/client

# dependencies:
# drizzle-orm 0.30.10
# └── @libsql/client 0.6.0 peer

The drizzle-kit commands (e.g. migrate, studio) finds it and uses it instead.

LibsqlError: URL_INVALID: The URL is not in a valid format
    at parseUri (file:///path-to-workspace/node_modules/.pnpm/@libsql+core@0.6.0/node_modules/@libsql/core/lib-esm/uri.js:9:15)

Ability to specify the better-sqlite3 driver is no longer available.

AlexBlokh commented 6 months ago

it might not be in dependencies in package.json, but still be in node modules, I suppose if you delete node modules and install again - it should work just fine

hyunbinseo commented 6 months ago

Finally found a reproduction:

pnpm -v # 9.1.0

pnpm i drizzle-orm @libsql/client -D
# devDependencies:
# + @libsql/client 0.6.0
# + drizzle-orm 0.30.10

pnpm rm @libsql/client
# devDependencies:
# - @libsql/client 0.6.0

rm -rf node_modules

pnpm i --force
# devDependencies:
# + drizzle-orm 0.30.10

The node_modules/.pnpm/@libsql+client@0.6.0 directory persists.

# pnpm-lock.yaml

lockfileVersion: '9.0'

settings:
  autoInstallPeers: true
  excludeLinksFromLockfile: false

importers:

  .:
    devDependencies:
      drizzle-orm:
        specifier: ^0.30.10
        version: 0.30.10(@libsql/client@0.6.0)

packages:

  '@libsql/client@0.6.0':
    resolution: {integrity: sha512-qhQzTG/y2IEVbL3+9PULDvlQFWJ/RnjFXECr/Nc3nRngGiiMysDaOV5VUzYk7DulUX98EA4wi+z3FspKrUplUA==}

The workaround is to:

pnpm rm drizzle-orm
pnpm i drizzle-orm -D
# Update pnpm lockfile
# pnpm-lock.yaml

importers:

  .:
    devDependencies:
      drizzle-orm:
        specifier: ^0.30.10
        version: 0.30.10
rm -rf node_modules
pnpm i --force

For pnpm monorepo,