[BUG]:Drizzle-Kit 0.19.0 Fails to Generate Migrations
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
Can you show your drizzle.config.ts file?
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;
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;
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.
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
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.
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.
Also dealing with this, using windows 11
Thanks we’re fixing that. Seems like it’s an issue with a Windows only Will update you here after fix is ready
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.
@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:
@xinha-sh update ESBuild, fixed for me
@miljan-code @TiltedToast can you please try drizzle-kit@win
@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 what version of node?
@AlexBlokh 18.16.0
@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
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.
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 please try npm i -D drizzle-kit@win