prisma: Next.js build: `RangeError: Maximum call stack size exceeded` in `typescript.js` when using TypeScript 5.1.3
Bug description
While using Prisma and Mongoose during the execution of “npm run build”, I’m receiving an error even with the simplest possible schema creation code.
> Build error occurred
RangeError: Maximum call stack size exceeded
at couldContainTypeVariables (/node_modules/typescript/lib/typescript.js:65159:39)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65453:14)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11)
at inferFromTypes (/node_modules/typescript/lib/typescript.js:65459:11) {
type: 'RangeError'
}
After several hours of searching for the problem in a larger project, I have established several facts:
- The problem only pertains to the latest version of TypeScript 5.1.3
- The error only occurs if a PrismaClient query is first executed, and only then is the Mongoose schema defined.
- In my case, the problem was caused by the Mongoose library, but it’s possible that someone may encounter such a problem with another library as well.
Has anyone encountered a similar problem and can suggest how to solve it?
How to reproduce
npx create-next-app@latest
- Change into created folder
npm install prisma --save-dev
npm install @prisma/client mongoose
npx prisma init --datasource-provider sqlite
- Add Test schema
model Test { id Int @id @default(autoincrement()) name String }
npx prisma generate
- Create
lib/test.ts
file with a content (it is the example code that illustrates the problem):import { PrismaClient } from '@prisma/client' import mongoose from 'mongoose'; new PrismaClient().test.create({ data: { name: "test", }, }); new mongoose.Schema({ site: String });
npm run build
Expected behavior
Error-free project build.
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Test {
id Int @id @default(autoincrement())
name String
}
new PrismaClient().test.create({
data: {
name: "test",
},
});
Environment & setup
- OS: macOS
- Database: SQLite
- Node.js version: v18.16.0
- TypeScript: 5.1.3
- Next.js: 13.4.5
Prisma Version
prisma : 4.15.0
@prisma/client : 4.15.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 8fbc245156db7124f997f4cecdd8d1219e360944 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 8fbc245156db7124f997f4cecdd8d1219e360944 (at node_modules/@prisma/engines/migration-engine-darwin)
Format Wasm : @prisma/prisma-fmt-wasm 4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944
Default Engines Hash : 8fbc245156db7124f997f4cecdd8d1219e360944
Studio : 0.484.0
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 36 (11 by maintainers)
Commits related to this issue
- removing sharp because https://github.com/prisma/prisma/issues/19715 — committed to trade-on/chat-evo by yokjim 4 months ago
I had this issue as well while testing with Typescript 5.1.3. I just upgraded to Typescript v5.1.6 and my code seems to run without issues again. I suggest you give it a try and see if it helps fixing your problem too.
I upgraded to v5.1.6 (the latest as per the npm package) not 5.1.5. Version 5.1.5 does not work, 5.1.6 does work.
Tailwind or Typescript?
Removing the Sharp package solved the problem for me. It seems that the Sharp package was causing conflicts or issues, and removing it resolved the issue.
@thanosoncode @phihungtf Optimally the TypeScript team releases a new patch version and you would switch to that instead of using the “dev” version.
Meanwhile, I think adding this in your package.json would unblock your projects
Or alternatively adding
--force
or--legacy-peer-deps
tonpm i
like mentioned in the error message (Vercel docs to customize the command here).We dug a bit deeper:
There are two related issues in the Typescript repo: https://github.com/microsoft/TypeScript/issues/54618 + https://github.com/microsoft/TypeScript/issues/54549 The second mentions that the
5.2.0-dev
version might already fix this, and indeed:5.2.0-dev.20230605
is still broken, but5.2.0-dev.20230606
works again.For me removing the package “sharp” from package.json resolved the issue.
A temporary workaround might be to downgrade to the previous
typescript
version:npm install typescript@5.0.4
confirmed!
This next13 drives me a lot of bugs
I’m observing the same error with
"typescript": "^5.2.2"
building my next.js app:To get it to build on Vercel, I had to make my build script set the stack-size to 5000.
@janpio Starting with typescript 5.1.3, it is no longer necessary to give @ts-expect-error to the server component. However, updating to 5.1.3 is causing the same error as this issue
Vercel Build log:
Currently my project is downgrading a dependency to temporarily avoid the error.