drizzle-orm: [BUG]: ERROR: Transforming const to the configured target environment ("es5") is not supported

What version of drizzle-orm are you using?

0.27.0

What version of drizzle-kit are you using?

0.19.2

Describe the Bug

Created a new next13 project and setup drizzle/drizzle kit using the quick start https://orm.drizzle.team/kit-docs/quick. Tried to run the generate script - dirzzle-kit generate:pg and got the following error:

Error: Transform failed with 1 error:
<path-to-app>/src/db/schema.ts:3:7: ERROR: Transforming const to the configured target environment ("es5") is not supported yet

errors: [
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [],
      pluginName: '',
      text: 'Transforming const to the configured target environment ("es5") is not supported yet'
    }
  ],

Downgrading to version 0.18.1 and 0.26.5 runs the generate command successfully not sure why this occurs with the latest version

Expected behavior

Run generate migrations successfully with drizzle kit version 0.19.2 and nextjs 13

Environment & setup

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 17
  • Comments: 17 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s another solution without creating an extra tsconfig.json, just hard code the target option.

I’m using pnpm patch to patch this.

diff --git a/index.cjs b/index.cjs
index b913e366250329eb9a6684fe711af908a1f8d75e..3b8a20975cdb47b8fd972fcd059ad7beef680371 100755
--- a/index.cjs
+++ b/index.cjs
@@ -11148,7 +11148,7 @@ var require_node2 = __commonJS({
           sourcefile: filename,
           loader: getLoader(filename),
           sourcemap: "both",
-          target: options.target,
+          target: "es6",
           jsxFactory: options.jsxFactory,
           jsxFragment: options.jsxFragment,
           format,

Next.js has es5 configured as its default and I assume not without reason. What is your suggestion?

es5 as a target is not supported, just try to use higher versions. es6 should work well

Workaround for now is to change the target in your tsconfig to ESNext when you want to run the drizzle-kit commands:


{
  "compilerOptions": {
    // "target": "es5", // nextjs default
    "target": "ESNext", // temporary override when using drizzle-kit
    /* ... */
}

es5 as a target is not supported, just try to use higher versions. es6 should work well

I’d still like to see a fix on the Drizzle kit side - I don’t think drizzle kit should be stuck using the same tsconfig as the src directory - drizzle kit shouldn’t cause clashes like this.

@andresgutgon I’m not a contributor to Drizzle, hopefully this issue has been seen by the Drizzle team. Unfortunately Drizzle-kit is not open source at the moment so we can’t submit pull request fixes even if we wanted to.

Ok, I think I found a better way:

I created a file called tsconfig.drizzle.json with these contents:

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "target": "ESNext",
  },
}

I then patched the node_modules/drizzle-kit/index.cjs by replacing all instances of tsconfig.json with tsconfig.drizzle.json.

I got this patch from using patch-package:

diff --git a/node_modules/drizzle-kit/index.cjs b/node_modules/drizzle-kit/index.cjs
index b75ca3b..5b115da 100644
--- a/node_modules/drizzle-kit/index.cjs
+++ b/node_modules/drizzle-kit/index.cjs
@@ -10402,7 +10402,7 @@ var require_node2 = __commonJS({
       }
       function resolveConfigPath(cwd, filename) {
         if (filename) {
-          var absolutePath = fs32.lstatSync(filename).isDirectory() ? path3.resolve(filename, "./tsconfig.json") : path3.resolve(cwd, filename);
+          var absolutePath = fs32.lstatSync(filename).isDirectory() ? path3.resolve(filename, "./tsconfig.drizzle.json") : path3.resolve(cwd, filename);
           return absolutePath;
         }
         if (fs32.statSync(cwd).isFile()) {
@@ -10415,7 +10415,7 @@ var require_node2 = __commonJS({
         if (existsSync4 === void 0) {
           existsSync4 = fs32.existsSync;
         }
-        var configPath = path3.join(directory, "./tsconfig.json");
+        var configPath = path3.join(directory, "./tsconfig.drizzle.json");
         if (existsSync4(configPath)) {
           return configPath;
         }
@@ -10711,7 +10711,7 @@ var require_node2 = __commonJS({
         if (!loadResult.tsConfigPath) {
           return {
             resultType: "failed",
-            message: "Couldn't find tsconfig.json"
+            message: "Couldn't find tsconfig.drizzle.json"
           };
         }
         if (!loadResult.baseUrl) {
@@ -10922,7 +10922,7 @@ var require_node2 = __commonJS({
     });
     var getOptions = (cwd) => {
       var _a, _b, _c, _d;
-      const { data, path: path3 } = joycon.loadSync(["tsconfig.json", "jsconfig.json"], cwd);
+      const { data, path: path3 } = joycon.loadSync(["tsconfig.drizzle.json", "jsconfig.json"], cwd);
       if (path3 && data) {
         return {
           jsxFactory: (_a = data.compilerOptions) == null ? void 0 : _a.jsxFactory,

Edit: see my other reply below instead, this doesn’t work

Additionally, if you want to just fix that with patch-package then you can use this patch:

diff --git a/node_modules/drizzle-kit/index.cjs b/node_modules/drizzle-kit/index.cjs
index b75ca3b..2c41c65 100644
--- a/node_modules/drizzle-kit/index.cjs
+++ b/node_modules/drizzle-kit/index.cjs
@@ -10441,6 +10441,7 @@ var require_node2 = __commonJS({
         var configString = readFileSync4(configFilePath);
         var cleanedJson = StripBom(configString);
         var config = JSON5.parse(cleanedJson);
+        config.compilerOptions.target = "ESNext";
         var extendedConfig = config.extends;
         if (extendedConfig) {
           if (typeof extendedConfig === "string" && extendedConfig.indexOf(".json") === -1) {

See https://dev.to/zhnedyalkow/the-easiest-way-to-patch-your-npm-package-4ece

es5 as a target is not supported, just try to use higher versions. es6 should work well

Thank you for the suggestion! I tried using es6 as the target and it worked well.

Actually @samhithk I think I may have not got the patch correct. I thought it was working but now I am not sure - I’m still tinkering so I will post again if I get more info