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

[BUG]:Drizzle-Kit 0.19.0 Fails to Generate Migrations

Open miljan-code opened this issue 3 years ago • 47 comments

What version of drizzle-orm are you using?

0.27.0

What version of drizzle-kit are you using?

0.19.0

Describe the Bug

I was using Drizzle Kit version of 0.18.1 and generating migrations with this command.

drizzle-kit generate:pg --config=drizzle.config.ts

As soon as I updated drizzle-kit to 0.19.0 version this command doesn't work anymore throwing the error

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected a url string to be returned for the "url" from the "drizzle-kit/loader.mjs 'resolve'" function but got instance of String.

Expected behavior

No response

Environment & setup

No response

miljan-code avatar Jun 17 '23 07:06 miljan-code

Can you show your drizzle.config.ts file?

AndriiSherman avatar Jun 17 '23 08:06 AndriiSherman

import type { Config } from 'drizzle-kit';

if (!process.env.DATABASE_URL) {
  throw new Error('DATABASE_URL is missing');
}

export default {
  schema: './db/schema.ts',
  out: './db/migrations',
  connectionString: process.env.DATABASE_URL,
} satisfies Config;

miljan-code avatar Jun 17 '23 08:06 miljan-code

Will add an error for deprecated Config keys in a patch release. 1-2 hours

But the reason is that there are breaking changes in 0.19.0 release. You can check the release notes for that: https://github.com/drizzle-team/drizzle-kit-mirror/releases/tag/v0.19.0

You need to write it this way now

import type { Config } from 'drizzle-kit';

if (!process.env.DATABASE_URL) {
  throw new Error('DATABASE_URL is missing');
}

export default {
  schema: './db/schema.ts',
  out: './db/migrations',
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL,
  }
} satisfies Config;

AndriiSherman avatar Jun 17 '23 08:06 AndriiSherman

Unfortunately, the error still persists. I'm using the same schema and migration generate command as before in 0.18.1 and have updated the drizzle.config.ts as you have mentioned, but am still getting an error.

Here is the link to the repo if somebody wants to inspect it.

miljan-code avatar Jun 17 '23 08:06 miljan-code

So, I just cloned your repo, and it worked fine for me. The only thing I've added is import 'dotenv/config' to make sure that the connection string was in the environment variables.

import type { Config } from 'drizzle-kit';
import 'dotenv/config'

if (!process.env.DATABASE_URL) {
  throw new Error('DATABASE_URL is missing');
}

export default {
  schema: './db/schema.ts',
  out: './db/migrations',
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DATABASE_URL,
  },
} satisfies Config;

and did get the migrations generated

AndriiSherman avatar Jun 17 '23 09:06 AndriiSherman

I'm also getting this error, am on Windows 11 if that helps. Never used drizzle before I just copied the config from the docs.

m11m avatar Jun 17 '23 09:06 m11m

Yes. I've just spin up a new VM instance (linux) and everything works fine. Something strange is going on my machine (windows), so I decided to downgrade kit and orm and everything works again.

miljan-code avatar Jun 17 '23 09:06 miljan-code

Also dealing with this, using windows 11

tdortman avatar Jun 17 '23 18:06 tdortman

Thanks we’re fixing that. Seems like it’s an issue with a Windows only Will update you here after fix is ready

AndriiSherman avatar Jun 17 '23 18:06 AndriiSherman

The temporary solution I used was to just switch to WSL. This obviously won't work for everyone and every project. So far no more issues.

MikeBooon avatar Jun 18 '23 01:06 MikeBooon

@AndriiSherman also experiencing this error when using with SST

import type { Config } from "drizzle-kit";

const connection = {
  connectionString: process.env["SST_Secret_value_NEON_CONNECTION_STRING"]!,
};

export default {
  out: "./migrations/",
  schema: "./src/db/schema.sql.ts",
  driver: "pg",
  dbCredentials: {
    connectionString: connection.connectionString,
  }
} satisfies Config;

Even tried this but same error:

import type { Config as DrizzleConfig } from "drizzle-kit";
import { Config } from "sst/node/config";

const dbConfig = {
  out: "./migrations/",
  schema: "./src/db/schema.sql.ts",
  driver: "pg",
  dbCredentials: {
    connectionString: Config.NEON_CONNECTION_STRING,
  }
} satisfies DrizzleConfig;

export default dbConfig;

Error screenshot:

Screenshot 2023-06-18 at 10 50 54 AM

heyshubhamsinha avatar Jun 18 '23 05:06 heyshubhamsinha

@xinha-sh update ESBuild, fixed for me

AlexBlokh avatar Jun 18 '23 05:06 AlexBlokh

@miljan-code @TiltedToast can you please try drizzle-kit@win

AlexBlokh avatar Jun 18 '23 08:06 AlexBlokh

@AlexBlokh still getting an error.

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected undefined or a fully resolved URL string to be returned for the "responseURL" from the "drizzle-kit/loader.mjs 'load'" function but got instance of String.

miljan-code avatar Jun 18 '23 09:06 miljan-code

@miljan-code what version of node?

AlexBlokh avatar Jun 18 '23 09:06 AlexBlokh

@AlexBlokh 18.16.0

miljan-code avatar Jun 18 '23 09:06 miljan-code

@AlexBlokh Tried it out with the new version, getting a different error now

> drizzle-kit push:mysql --config ./src/db/drizzle.config.ts

node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@esbuild-kit/esm-loader' imported from E:\coding-projects\hifumi-js\
Did you mean to import @[email protected]/node_modules/@esbuild-kit/esm-loader/dist/index.js?
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:889:9)
    at moduleResolve (node:internal/modules/esm/resolve:938:20)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)       
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at initializeLoader (node:internal/process/esm_loader:75:58)
    at loadESM (node:internal/process/esm_loader:90:11) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.16.0

It seems to just fail on any drizzle-kit command now with this error

tdortman avatar Jun 18 '23 12:06 tdortman

Can confirm that I am getting the same on Mac.

Using latest version 0.19.0

Latest config and everything based on the new release notes.

Screenshot 2023-06-18 at 21 04 00

rajeshdavidbabu avatar Jun 18 '23 19:06 rajeshdavidbabu

I have my schema split into multiple files and that causes it to now fail with Error [ERR_MODULE_NOT_FOUND]. If I move everything into 1 schema file, then it starts working, but only if I'm not importing anything from a another file (e.g. ./shared)

amosbastian avatar Jun 19 '23 08:06 amosbastian

@amosbastian please try npm i -D drizzle-kit@win

AlexBlokh avatar Jun 19 '23 08:06 AlexBlokh