drizzle-orm: [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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 8
  • Comments: 47 (15 by maintainers)

Most upvoted comments

We’ve decided to rollback ESM support for drizzle-kit, as it was causing a lot of issues on Windows and some issues on Mac. We want to unblock drizzle-kit and give all of you the opportunity to get new ORM and kit updates.

Note: all new features will be still available. We just rollbacked esm settings that we thought should work

We have gathered a lot of feedback, and errors have appeared. Additionally, we have managed to set up proper test environments for Windows, Mac, and Linux, which has been really helpful.

We will be working on improvements on another branch at a pace that suits us, so that we can ensure we are not blocking anyone here.

Thank you all for your patience and for reporting the issues and sharing information!

The rollback is already available under the drizzle-kit@cjs tag and will be included in the latest version today

I am surprised to see that drizzle-kit is not open-source. All we can do is complain 😑

@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 @esbuild-kit+esm-loader@2.5.5/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 in a brand new and latest dependencies version of next 13 changing tsconfig’s target to esnext definitely worked. i originally tried to change the lib but noticed it was already set to esnext, then noticed that its actually the target field that needs to be set!

Additionally, I noticed that the auto-generated tsconfig.json file for Next.js had its compilerOptions.target set to “es5.” To investigate whether ESBUILD might be using my root directory’s tsconfig.json as a parameter for the compilation target, I changed this value to “ESNext.” I then attempted to run the migration again using the original setup (TypeScript files in a schema folder, each containing a table definition). This time, the migration ran successfully, and all tables and columns were created as expected.

I still don’t get mine to work. Removed the node_modules folder and re-installed. But the only thing you had to do was to change the target of the tsconfig.json target to “ESNext”?. Did you still use the drizzle-kit@cjs package?

My tsconfig.json already has target: "ESNext" and it doesn’t work so might not be a fix for everyone.

hmmmm, I see

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)

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

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.