typegraphql-prisma icon indicating copy to clipboard operation
typegraphql-prisma copied to clipboard

EMFILE: too many open files

Open cre8tiv opened this issue 4 years ago • 14 comments

Describe the Bug I have a prisma.schema with 202 tables, when running npx prisma generate I get the message: Error: EMFILE: too many open files. I then modified the schema to have 153 tables to test and ran the command again and it failed. I then tried with 100 tables and it failed. I tried it with 57 tables, and it failed. My schema is generated from a prisma db pull to an existing MS SQL server database.

  • OS: Windows 11
  • Node 14.17.0
  • typegraphql-prisma 0.16.3
  • Prisma version: 3.3.0
  • TypeScript: 4.4.4

cre8tiv avatar Nov 09 '21 20:11 cre8tiv

I am also facing the same issue after adding a few models to the schema.

sagarsneh avatar Nov 09 '21 21:11 sagarsneh

@cre8tiv @sagarsneh Please try the "source code" generation mode:

generator typegraphql {
  provider           = "typegraphql-prisma"
  output             = "../prisma/generated/typegraphql-prisma"
  emitTranspiledCode = false
}

ts-morph is not good at compiling the generated TS files into *.js and *.d.ts files.

MichalLytek avatar Nov 10 '21 09:11 MichalLytek

I added this to my schema.prisma file and then attempted to run the generate command with 153 models. I still got the same error message. When I checked the output, I had the expected number of files in the models folder, but the error message indicated that it seemed to fail in files for \resolvers\outputs. I commented out many of the models in my schema and was able to get it to run successfully with 57 models.

cre8tiv avatar Nov 10 '21 13:11 cre8tiv

Hi I am having the same issue. My schema is not that big. schema.zip Without emitTranspiledCode = false flag I am getting 'too many open files error', but when I add emitTranspiledCode = false generation succedes. When server is started I got this error:

import * as crudResolversImport from "./resolvers/crud/resolvers-crud.index";
^^^^^^
SyntaxError: Cannot use import statement outside a module

I guess there must be some circular references or similar. Any any help will do, library is just perfect!!

jlavric avatar Nov 15 '21 11:11 jlavric

@jlavric

Cannot use import statement outside a module

You need to emit those source files into your src directory, not node_modules. They have to be compiled by TypeScript.

MichalLytek avatar Nov 15 '21 11:11 MichalLytek

@MichalLytek thank you for quick response. Yes of course I forgot that, my mistake. With generated files in my src directory and properly imported I was getting this error: RangeError: Maximum call stack size exceeded. at ... \src\generated\type-graphql\resolvers\inputs\ComponentCreateNestedOneWithoutUcsInput.ts:1:1) That is why I am thinking about circular references.

jlavric avatar Nov 15 '21 11:11 jlavric

I have done a lot of testing and research and finally it works for me. I just have to change some steps. I can confirm that with emitTranspiledCode = false switch in schema typegraphql-prisma generation works as it should. I can't run my project now with ts-node because of RangeError: Maximum call stack size exceeded. So I had to compile wiht tsc and add generated code. With that I got graphql server with generated resolvers and it works on debian, rhel (CentOS) and windows servers.

Part of my package.json "dependencies": { "@prisma/client": "^3.4.2", "apollo-server-express": "^3.5.0", "class-validator": "^0.13.1", "colors": "^1.4.0", "cors": "^2.8.5", "crypto-js": "^4.1.1", "formidable": "^2.0.1", "fs-extra": "^10.0.0", "graphql": "^15.7.2", "graphql-fields": "^2.0.3", "graphql-scalars": "1.10", "jsonwebtoken": "^8.5.1", "moment": "^2.29.1", "pdfmake": "^0.2.4", "reflect-metadata": "^0.1.13", "ts-node": "^10.4.0", "type-graphql": "^1.1.1" }

jlavric avatar Nov 16 '21 08:11 jlavric

Hi, our model has nearly 120 tables and we just got this same error. Any update on this issue?

GreenOn avatar Dec 17 '22 03:12 GreenOn

Splitting the schema is hard since there are so many relations and especially prisma asks us to tie all these tables with FKs.

GreenOn avatar Dec 17 '22 03:12 GreenOn

Update: I switched to a high performance linux machine and I was able to run it to completion.

GreenOn avatar Dec 17 '22 05:12 GreenOn

Could this be fixed by switching usage of fs to graceful-fs?

I was able to work around this by monkeypatching typegraphql-prisma globally: https://github.com/isaacs/node-graceful-fs#global-patching

mmmeff avatar Apr 06 '23 00:04 mmmeff

@mmmeff Apart from tests, I use fs only to remove and create the output dir. Please ask on ts-morph repo about this issue, I don't know if underlying tsc is not using fs directly.

MichalLytek avatar Apr 06 '23 06:04 MichalLytek

Has there been any type of resolution or workaround for this? Running into this now and my team is trying to solve this issue

UPDATE: We fixed the issue by setting emitTranspilerCode = false and compiling with tsc (npx tsc) with a tsconfig.json file.

caseyDev422 avatar Jul 12 '23 13:07 caseyDev422