maximum call stack exceeded

Tthdxr4/4/2023
Weird bug where whenever I add a where eq clause getting maximum call stack exceeded
Tthdxr4/4/2023
debugging more right now
Tthdxr4/4/2023
angeError: Maximum call stack size exceeded
at <anonymous> (/home/thdxr/dev/projects/goodvisit/saguaro/node_modules/.pnpm/drizzle-orm@0.23.5_psajsodr3yuurl4pn54idjatoy/node_modules/drizzle-orm/sql/index.js:62:17)
Tthdxr4/4/2023
return { sql: chunk.value.join(''), params: [] };
ASAndrii Sherman4/4/2023
:sweating:
ASAndrii Sherman4/4/2023
Is it MySQL?
Tthdxr4/5/2023
no postgres
Tthdxr4/5/2023
I must be doing something wrong
ASAndrii Sherman4/5/2023
if you could send example of query to reproduce it
ASAndrii Sherman4/5/2023
we can check it
Jjeanhdev4/22/2023
Hey, I'm facing a similar issue - any update on this ? Thanks !
UUUnknown User4/23/2023
Message Not Public
Sign In & Join Server To View
Bbloberenober4/23/2023
yes, I think this is related to having multiple instances of drizzle installed
@thdxr @jeanhdev @michmich this should be resolved by installing drizzle-orm to the workspace root using -w
in the meantime, we already have an issue to improve this - https://github.com/drizzle-team/drizzle-orm/issues/283
Jjeanhdev4/23/2023
Yes, I fixed it by installing globally on the turborepo w/ the -w flag ! @bloberenober helped me 💯
UUUnknown User4/23/2023
Message Not Public
Sign In & Join Server To View
Bbloberenober4/23/2023
yes, you need to have a single version for all the projects
Bbloberenober4/23/2023
so you need to remove them anywhere except the root
Ss1njar4/29/2023
This problem is still present when I dump the drizzle package to a custom db package and build that.
Then it doesn't make difference if i'm going to install it globally or not.

Are there any plans to fix this issue in the near future:
https://github.com/drizzle-team/drizzle-orm/issues/283
Bbloberenober4/29/2023
It's not a top priority right now, but might be one of the next tasks
Bbloberenober4/29/2023
so it may be done within a month
Ss1njar4/29/2023
I see. Good 2 know. Thank you 🙂
Ddoiská4/30/2023
Hi, there's any other workaround? Even without turborepo/monorepo couldn't fix it.
drizzle-orm: > 0.25 gives me this error
drizzle-orm: 0.24 works fine

The stacktrace took me to this file: https://github.com/drizzle-team/drizzle-orm/blob/aadde621556ce61722be2f2b23c8ec66c3408c49/drizzle-orm/src/sql/index.ts#L129
Ss1njar4/30/2023
@doiská Could be the same issue. Do you use drizzle directly in your frameworks ?
Ddoiská4/30/2023
Yes, but i tried both installing in workspace root and package root, same result. Even moving packages to "single projects"
Ddoiská4/30/2023
Weirdly if i use at index with iife, all queries seems to work again
Ss1njar4/30/2023
You should avoid to build the package by your own with tsup or tsc
Ddoiská4/30/2023
Oh, mb, i was talking about my projects. Im not rebuilding drizzle
Ddoiská4/30/2023
I rebuilt without turbo repo/any workspace
Ss1njar4/30/2023
Oh i see. I thought cause you mentioned the monorepo. Could you show an example how your structure looks like ?
Ddoiská4/30/2023
Do you mean folder structure?
Ss1njar4/30/2023
Exactly
Ddoiská4/30/2023
If it helps, i can share the repository in private
Ddoiská4/30/2023
The server is where drizzle is being used
Ddoiská4/30/2023
The build is made using esbuild with context api, some settings are: node16, bundle, alias '@' and loader ts
Ddoiská4/30/2023
rn, drizzle is installed as server (package) dependency
Ss1njar4/30/2023
Mhm and used nowhere else than inside the server ?
Is the server custom made or built with any framework like nestjs ?
Ddoiská4/30/2023
Custom made, right now just using express and some event emitters, no big deal
Ddoiská4/30/2023
Theres one more thing, for every endpoint call, i use a setImmediate with promise resolving the response. Just to be similar to the way FiveM works
Ddoiská4/30/2023
And no, its not being used anywhere outside server.
Ddoiská4/30/2023
I tried removing it, no difference
Ddoiská4/30/2023
The only way i made > 0.25 works was inside a iife, idk why
Ddoiská4/30/2023
If i use drizzle directly:

  @NetPromise(TwitterEvents.TweetList)
  async test() {

    const response = await db
        .select()
        .from(twitterUsers)
        .innerJoin(twitterActions, eq(twitterActions.id, twitterUsers.id));

    console.log(response);

    // return {
    //   status: 'ok',
    //   data: []
    // }
  }


It gives me the error, but using an import, it works:
import { getTweets } from "@server/apps/twitter/twitter-tweets.db";

  @NetPromise(TwitterEvents.TweetList)
  async test() {

    const response = await getTweets();
    console.log(response);

    // return {
    //   status: 'ok',
    //   data: []
    // }
  }
Ss1njar4/30/2023
@doiská If you use it directly it get built twice i guess. And thats the same issue then like with monorepos mentioned above. Seems we need to wait for that fix.
SSiris4/30/2023
im using a normal monorepo without any tools like turborepo.

Basically i have a config folder which has the schema file for drizzle + deps
Then i have 2 apps, each will run on their own docker container, the config folder will be copied to both of the containers.

What would be the workaround here?
The monorepo consists of more apps written in different langauges and i do not want to install npm packages at the root level
SSiris4/30/2023
Im doing something like this for now which works, but i hope this issue gets a proper solution soon

RUN rm -rf ./foo/node_modules/drizzle-orm
RUN rm -rf ./bar/node_modules/drizzle-orm
RUN pnpm add --global drizzle-orm pg
RUN pnpm --dir ./foo link --global drizzle-orm pg
RUN pnpm --dir ./bar link --global drizzle-orm pg
Ddoiská5/1/2023
I think I get it, my problem only happens when I bundle the drizzle-orm using esbuild. If i set it as externals, it works perfectly
Ddoiská5/1/2023
My esbuild config

    entryPoints: [
      './src/server/index.ts'
    ],
    outfile: './dist/server/server.js',
    bundle: true,
    sourcemap: true,
    loader: {
      '.ts': 'ts',
    },
    platform: 'node',
    target: 'node16',
    format: 'cjs',
    external: ['drizzle-orm'],
    define: {
      'process.env.NODE_ENV': `"${process.env.NODE_ENV || 'development'}"`
    },
    plugins: [
      esbuildDecorators({
        tsconfig: './src/server/tsconfig.json'
      })
    ],
    tsconfig: './src/server/tsconfig.json',
Ddoiská5/1/2023
Thanks @Siris @s1njar ^^
Tthdxr5/18/2023
those of you with the problem, what version of pnpm do you have?
Hhachoter5/30/2023
I have the same issue now with latest version of pnpm without turborepo
SSilver.5/30/2023
I'm also facing this issue,
pnpm 7.27.1
turbo: 1.10.0
drizzle-orm: 0.26.3
@planetscale/database: 1.7.0