Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prisma@4.7.1 - "RangeError: Maximum call stack size exceeded" when clientExtensions enabled #16600

Closed
JoeKarow opened this issue Dec 2, 2022 · 29 comments · Fixed by #16856 or #16936
Closed
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions topic: previewFeatures Issue touches on an preview feature flag topic: prisma-client topic: RangeError Maximum call stack size exceeded
Milestone

Comments

@JoeKarow
Copy link

JoeKarow commented Dec 2, 2022

Bug description

Enabling clientExtensions feature causes TypeScript failure.

RangeError: Maximum call stack size exceeded
    at getResolvedMembersOrExportsOfSymbol (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:48886:53)
    at getMembersOfSymbol (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:48932:19)
    at isEmptyAnonymousObjectType (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:54984:60)
    at Object.some (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:663:25)
    at getNormalizedUnionOrIntersectionType (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:55142:44)
    at getNormalizedType (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:55128:48)
    at isRelatedTo (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:55440:30)
    at typeRelatedToEachType (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:55751:35)
    at unionOrIntersectionRelatedTo (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:55687:28)
    at structuredTypeRelatedToWorker (/Users/joe/Library/pnpm/global/5/.pnpm/typescript@4.9.3/node_modules/typescript/lib/tsc.js:56024:34)

How to reproduce

Please see notes on reproduction repository README: https://github.com/JoeKarow/prisma4.7.1-reproduce

Expected behavior

No response

Prisma information

Prisma schema: https://github.com/JoeKarow/prisma4.7.1-reproduce/blob/main/prisma/schema.prisma

Environment & setup

  • OS: macOS 13.0.1 Intel
  • Database: PostgreSQL
  • Node.js version: 16.18.1

Prisma Version

Environment variables loaded from .env
prisma                  : 4.7.1
@prisma/client          : 4.7.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/.pnpm/@prisma+engines@4.7.1/node_modules/@prisma/engines/prisma-fmt-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.1-1.272861e07ab64f234d3ffc4094e32bd61775599c
Default Engines Hash    : 272861e07ab64f234d3ffc4094e32bd61775599c
Studio                  : 0.477.0
Preview Features        : multiSchema, filteredRelationCount, fieldReference, postgresqlExtensions, clientExtensions
@tavindev
Copy link

tavindev commented Dec 4, 2022

Same here. Looks like a circular dependency thing.

@kachar
Copy link

kachar commented Dec 4, 2022

Same here

Exception has occurred: RangeError: Maximum call stack size exceeded
  at getResolvedMembersOrExportsOfSymbol (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:59024:53)
    at getMembersOfSymbol (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:59079:19)
    at isEmptyAnonymousObjectType (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:65891:90)
    at Object.some (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:748:25)
    at getNormalizedUnionOrIntersectionType (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:66056:73)
    at getNormalizedType (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:66042:84)
    at isRelatedTo (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:66404:30)
    at isPropertySymbolTypeRelated (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:67746:24)
    at propertyRelatedTo (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:67789:31)
    at propertiesRelatedTo (/app/cells/graph-api/node_modules/typescript/lib/typescript.js:67990:43)

@eviefp eviefp added the team/client Issue for team Client. label Dec 5, 2022
@JoeKarow
Copy link
Author

JoeKarow commented Dec 5, 2022

@tavindev @kachar
Are you able to link your schemas so the Prisma team has more data available to them to be able to hunt down & fix this bug?

@kachar
Copy link

kachar commented Dec 5, 2022

@JoeKarow
Copy link
Author

JoeKarow commented Dec 5, 2022

@JoeKarow I believe @tavindev has shared his schema in the issue description - JoeKarow/prisma4.7.1-reproduce@main/prisma/schema.prisma

That's my schema 😄

@tavindev
Copy link

tavindev commented Dec 6, 2022

@tavindev @kachar Are you able to link your schemas so the Prisma team has more data available to them to be able to hunt down & fix this bug?

Unfortunately, it will not be possible to share my schema.

@ajhollowayvrm
Copy link

I'm having this same error too. For me it only happens when I actually try to use an extension not just enabling it.

export const DBConn = new PrismaClient({ log: [ { emit: 'event', level: 'query', }, { emit: 'stdout', level: 'error', }, { emit: 'stdout', level: 'info', }, { emit: 'stdout', level: 'warn', }, ], }).$extends({ name: 'user display name', result: { users: { displayName: { needs: { first_name: true, preferred_name: true }, compute(user) { return user.preferred_name || user.first_name; }, }, }, }, });

If I remove the .$extension part, everything works just fine. Starting it with ts-node.

[nodemon] watching extensions: ts,json [nodemon] starting ts-node ./src/api.ts /Users/ajholloway/programming/nectarbackend/node_modules/typescript/lib/typescript.js:66937 outofbandVarianceMarkerHandler = function (onlyUnreliable) { ^ RangeError: Maximum call stack size exceeded at outofbandVarianceMarkerHandler (/Users/ajholloway/programming/nectarbackend/node_modules/typescript/lib/typescript.js:66937:63)

@bn-piar
Copy link

bn-piar commented Dec 14, 2022

Next.js app fails to run when using custom server with clientExtension feature. Without the custom server it runs fine locally but fails to build at digital ocean's app platform.
Schema: https://pastebin.com/wPBPwvGE

@lipis
Copy link

lipis commented Dec 22, 2022

I installed the 4.8.0 and still have the issue when building a Next.js app with $extends

@mattbajorek
Copy link

Same issue hear without even using $extends just upgrading to 4.8.0 crashes our compilation.

@millsp
Copy link
Member

millsp commented Dec 22, 2022

Hey @lipis @mattbajorek, sorry that you're still experiencing this. We've fixed and tested the original reproduction case, but it seems there is more to it. Could you please provide us with a reproduction?

Update: Nevermind, I could reproduce it with a more complex schema

@millsp millsp reopened this Dec 22, 2022
@khalil-omer
Copy link

Confirmed this still exists in 4.8.0. $extends client method triggers this, as does Prisma.defineExtension.

@lipis
Copy link

lipis commented Dec 26, 2022

@millsp in case you still need my use case... here is what I did with $extend in my Next.js project: https://gist.github.com/lipis/7564e99b6315a3940dbcb1a5c1a413a9

@millsp
Copy link
Member

millsp commented Dec 27, 2022

Hey @lipis @mattbajorek @khalil-omer, I have been working on this in a an experimental branch and as part of a wider effort. I would really like to get this right for you guys, could you please try @prisma/client 4.9.0-integration-feat-client-ext-generic-type-api.11? On my side, I have tested it on a relatively huge & complex schema (~ +70 models).

@beeman
Copy link

beeman commented Dec 27, 2022

I got a similar error when I tried to override an existing optional property:

I would love to use it like this, providing a default value based on another field

  readonly prisma = new PrismaClient().$extends({
    result: {
      user: {
        name: {
          needs: { name: true, username: true },
          compute: (parent) => parent.name ?? parent.username,
        },
      },
    },
  })

When I pick another name it works:

  readonly prisma = new PrismaClient().$extends({
    result: {
      user: {
        another_name: {
          needs: { name: true, username: true },
          compute: (parent) => parent.name ?? parent.username,
        },
      },
    },
  })

It would be nice if this use case would be supported, or give an error at compile time.

.../node_modules/@prisma/client/runtime/index.js:31227
const resolveNeeds = /* @__PURE__ */ __name((fieldName) => {
^
  RangeError: Maximum call stack size exceeded
  at resolveNeeds (.../node_modules/@prisma/client/runtime/index.js:31227:47)
  at Array.flatMap (<anonymous>)
  at .../node_modules/@prisma/client/runtime/index.js:31230:48
  at Cache.getOrCreate (.../node_modules/@prisma/client/runtime/index.js:31199:19)
  at resolveNeeds (.../node_modules/@prisma/client/runtime/index.js:31228:18)
  at Array.flatMap (<anonymous>)
  at .../node_modules/@prisma/client/runtime/index.js:31230:48
  at Cache.getOrCreate (.../node_modules/@prisma/client/runtime/index.js:31199:19)
  at resolveNeeds (.../node_modules/@prisma/client/runtime/index.js:31228:18)
  at Array.flatMap (<anonymous>)

@khalil-omer
Copy link

khalil-omer commented Dec 27, 2022

@millsp Hi - looks like you are making progress with this. With your branch installed, the call stack error is gone and Prisma.defineExtension throws no tsc errors. However, $extends is now throwing the following error instead.

Exported variable 'pivotPrisma' has or is using name 'Payload' from external module "[path]/client/runtime/index" but cannot be named.

The above error is actually throwing many times. Not sure if that fact helps you debug.

CleanShot 2022-12-27 at 09 47 36

@millsp
Copy link
Member

millsp commented Dec 27, 2022

Hey @beeman, I think we've had another report of this here.

@millsp
Copy link
Member

millsp commented Dec 27, 2022

@khalil-omer Thanks, that's encouraging news. I had a quick try exporting a prisma client with an extension, but could not reproduce. Could you please share a minimal reproduction with me? If you have the time, I'd need a tsconfig and a small piece of code.

@khalil-omer
Copy link

@millsp this latest error appears to be related to declarations: true and declerationMaps: true. If I set both properties to false in the tsconfig, the error disappears and the build is successful.

As someone commented here, there is an outstanding bug with declarations. Maybe there should be a separate issue created for that.

@Multiply
Copy link

Multiply commented Jan 1, 2023

4.9.0-integration-feat-client-ext-generic-type-api.11

It seems like nested includes doesn't generate correct typescript definitions with this branch.

{
  include: {
    blocks: {
      include: {
        block: true,
      },
      orderBy: {
        sorting: 'asc',
      },
    },
    image: true,
  },
}

image

Edit:

@millsp this latest error appears to be related to declarations: true and declerationMaps: true. If I set both properties to false in the tsconfig, the error disappears and the build is successful.

With latest release, and these two set to false, I still get:

RangeError: Maximum call stack size exceeded
    at recursiveTypeRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:66871:44)
    at isRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:66477:25)
    at isPropertySymbolTypeRelated (/scrambled/node_modules/typescript/lib/typescript.js:67746:24)
    at propertyRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:67789:31)
    at propertiesRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:67990:43)
    at structuredTypeRelatedToWorker (/scrambled/node_modules/typescript/lib/typescript.js:67522:34)
    at structuredTypeRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:66991:30)
    at recursiveTypeRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:66956:30)
    at isRelatedTo (/scrambled/node_modules/typescript/lib/typescript.js:66477:25)
    at eachTypeRelatedToType (/scrambled/node_modules/typescript/lib/typescript.js:66793:41) {
  type: 'RangeError'
}

@janpio janpio added the bug/2-confirmed Bug has been reproduced and confirmed. label Jan 6, 2023
@millsp
Copy link
Member

millsp commented Jan 10, 2023

Thanks both, I was able to reproduce and thanks for the additional information.

@millsp
Copy link
Member

millsp commented Jan 11, 2023

Thanks to your help 4.9.0-integration-feat-client-ext-generic-type-api.13, should fix the export issue as well as the node inference issue @khalil-omer. Could you please give it a try? I am not 100% for you @Multiply since I was not able to reproduce this exact same error. If the issue persists, would you mind sending me your schema? As for the nested includes issue, I will fix it but treat it as a separate issue.

Many thanks for the help so far 👍

@Jolg42 Jolg42 modified the milestones: 4.8.0, 4.9.0 Jan 11, 2023
@jove4015
Copy link

I just ran into this problem today trying to move RLS from middleware into client extensions. The code actually works fine in development mode - but I can't make a production build because of the above error.

I tried using your branch 4.9.0-integration-feat-client-ext-generic-type-api.13, and while the recursion error goes away, I have errors all over my project now:
image

All in the same vein where the types of everything are just "never".

On a hunch I tried v.14, 15, 16, and 17 (which seems to be the latest one available) as well since I figured you were still working on this, but I'm still getting the same errors with "never".

Still, in dev mode, my app loads and functions properly. It's just a type resolution issue.

@TaylorFacen
Copy link

Hi, I'm running into this error as well. Using the 4.9.0 branch resolved the maximum call stack error, but now my nested values aren't typed. For example

Type error: Property 'post' does not exist on type '{ id: string; createdAt: Date; updatedAt: Date; postId: string; commentBody: string; }'.

Even though there aren't any type errors visible in VScode's linting and I am in fact querying the comment and the post
e.g.

prisma.comment.findFirstOrThrow({ where: { id: commentId }, include: { post: true } })

@millsp
Copy link
Member

millsp commented Jan 16, 2023

Hey @TaylorFacen, thanks for the report. Could you please create a separate issue?

@TaylorFacen
Copy link

Hey @TaylorFacen, thanks for the report. Could you please create a separate issue?

Done! #17349 . Let me know if you need any additional information.

@jove4015
Copy link

jove4015 commented Feb 6, 2023

@millsp - This bug is marked resolved, however, client extensions still are not usable (see #17767). Is there any progress on making this feature functionally available?

@WARDHAN10
Copy link

Can't seems to follow what is the actuals solution to this can anybody elaborate, getting the same issue

@millsp
Copy link
Member

millsp commented May 4, 2023

Hey @WARDHAN10, we have fixed this issue already, and the fix is available. Please update to our latest version, and if the problem persists, we'd love if you could open a new issue with a reproduction. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: clientExtensions topic: previewFeatures Issue touches on an preview feature flag topic: prisma-client topic: RangeError Maximum call stack size exceeded
Projects
None yet