DT
Drizzle Team•2y ago
thdxr

maximum call stack exceeded

Weird bug where whenever I add a where eq clause getting maximum call stack exceeded
39 Replies
thdxr
thdxrOP•2y ago
debugging more right now angeError: Maximum call stack size exceeded at <anonymous> (/home/thdxr/dev/projects/goodvisit/saguaro/node_modules/.pnpm/[email protected]_psajsodr3yuurl4pn54idjatoy/node_modules/drizzle-orm/sql/index.js:62:17) return { sql: chunk.value.join(''), params: [] };
Andrii Sherman
Andrii Sherman•2y ago
sweating it MySQL?
thdxr
thdxrOP•2y ago
no postgres I must be doing something wrong
Andrii Sherman
Andrii Sherman•2y ago
if you could send example of query to reproduce it we can check it
sevenwestonroads
sevenwestonroads•2y ago
Hey, I'm facing a similar issue - any update on this ? Thanks !
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Dan
Dan•2y ago
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
sevenwestonroads
sevenwestonroads•2y ago
Yes, I fixed it by installing globally on the turborepo w/ the -w flag ! @bloberenober helped me 💯
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Dan
Dan•2y ago
yes, you need to have a single version for all the projects so you need to remove them anywhere except the root
s1njar
s1njar•2y ago
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
Dan
Dan•2y ago
It's not a top priority right now, but might be one of the next tasks so it may be done within a month
s1njar
s1njar•2y ago
I see. Good 2 know. Thank you 🙂
doiská
doiská•2y ago
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
GitHub
drizzle-orm/index.ts at aadde621556ce61722be2f2b23c8ec66c3408c49 · ...
TypeScript ORM for SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
s1njar
s1njar•2y ago
@doiská Could be the same issue. Do you use drizzle directly in your frameworks ?
doiská
doiská•2y ago
Yes, but i tried both installing in workspace root and package root, same result. Even moving packages to "single projects" Weirdly if i use at index with iife, all queries seems to work again
s1njar
s1njar•2y ago
You should avoid to build the package by your own with tsup or tsc
doiská
doiská•2y ago
Oh, mb, i was talking about my projects. Im not rebuilding drizzle I rebuilt without turbo repo/any workspace
s1njar
s1njar•2y ago
Oh i see. I thought cause you mentioned the monorepo. Could you show an example how your structure looks like ?
doiská
doiská•2y ago
Do you mean folder structure?
s1njar
s1njar•2y ago
Exactly
doiská
doiská•2y ago
If it helps, i can share the repository in private
doiská
doiská•2y ago
The server is where drizzle is being used The build is made using esbuild with context api, some settings are: node16, bundle, alias '@' and loader ts rn, drizzle is installed as server (package) dependency
s1njar
s1njar•2y ago
Mhm and used nowhere else than inside the server ? Is the server custom made or built with any framework like nestjs ?
doiská
doiská•2y ago
Custom made, right now just using express and some event emitters, no big deal 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 And no, its not being used anywhere outside server. I tried removing it, no difference The only way i made > 0.25 works was inside a iife, idk why 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: []
// }
}
@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: []
// }
}
@NetPromise(TwitterEvents.TweetList)
async test() {

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

// return {
// status: 'ok',
// data: []
// }
}
s1njar
s1njar•2y ago
@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.
Siris
Siris•2y ago
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 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
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
doiská
doiská•2y ago
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 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',
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',
Thanks @Siris @s1njar ^^
thdxr
thdxrOP•2y ago
those of you with the problem, what version of pnpm do you have?
hachoter
hachoter•2y ago
I have the same issue now with latest version of pnpm without turborepo
TSilver
TSilver•2y ago
I'm also facing this issue,
pnpm 7.27.1
turbo: 1.10.0
drizzle-orm: 0.26.3
@planetscale/database: 1.7.0
pnpm 7.27.1
turbo: 1.10.0
drizzle-orm: 0.26.3
@planetscale/database: 1.7.0
Dan
Dan•2y ago
If you have a monorepo (with or without using turborepo), install drizzle-orm (and drizzle-kit/drizzle-zod, if you're using them) in the workspace root using -w
hachoter
hachoter•2y ago
@Dan Kochetov mind explaining why it's happening? I am just curious
Dan
Dan•2y ago
Because of how monorepo's dependencies work internally, there might be multiple Drizzle instances at runtime, even if it's installed once, which it currently cannot handle properly. It's one of my priorities for this month to fix.
Mini
Mini•2y ago
not working with yarn v3 workspaces 🤔 is there any solution? nvm. I was loading and using a package that creates drizzle instances. When I create instance in server workspace, it works fine.
Dan
Dan•2y ago
should work the same
walt_terry
walt_terry•2y ago
I don't have monorepo but still getting this same error when using where 🤔
polkovnik
polkovnik•2y ago
Can confirm, shit went south when drizzle was installed in multiple packages in mono.
Andrii Sherman
Andrii Sherman•2y ago
0.27.0 soon 👀
Want results from more Discord servers?
Add your server