toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
642 stars 106 forks source link

EMFILE: too many open files, watch '/app/src/i18n' #498

Closed aroshanzamir closed 1 year ago

aroshanzamir commented 1 year ago

After running (npm run build), I get the following error:

node:internal/errors:465
ErrorCaptureStackTrace(err);
^
Error: EMFILE: too many open files, watch '/app/src/i18n'
at FSWatcher.<computed> (node:internal/fs/watchers:244:19)
at Object.watch (node:fs:2264:34)
at createFsWatchInstance (/app/node_modules/chokidar/lib/nodefs-handler.js:119:15)
at setFsWatchListener (/app/node_modules/chokidar/lib/nodefs-handler.js:166:15)
at NodeFsHandler._watchWithNodeFs (/app/node_modules/chokidar/lib/nodefs-handler.js:331:14)
at NodeFsHandler._handleDir (/app/node_modules/chokidar/lib/nodefs-handler.js:567:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async NodeFsHandler._addToNodeFs (/app/node_modules/chokidar/lib/nodefs-handler.js:617:16)
at async /app/node_modules/chokidar/index.js:451:21
at async Promise.all (index 0)
Emitted 'error' event on FSWatcher instance at:
at FSWatcher._handleError (/app/node_modules/chokidar/index.js:647:10)
at NodeFsHandler._addToNodeFs (/app/node_modules/chokidar/lib/nodefs-handler.js:645:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /app/node_modules/chokidar/index.js:451:21
at async Promise.all (index 0) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
path: '/app/src/i18n',
filename: '/app/src/i18n'
}

How can I solve it?

rubiin commented 1 year ago

You can check the stack overflow https://stackoverflow.com/questions/8965606/node-and-error-emfile-too-many-open-files. If you are on linux , the answer is to increase the file watchers

azuken commented 2 months ago

We had the exact same issue on our CI (on local build was fine), I managed to resolve the issue by deactivating watch feature on translation json files (increase ulimit on machine, or docker build was not working). We do not need to have a watch feature on build, but maybe there is a leak, or something to deactivate on nest build to avoid this kind of issue.

app.module.ts

    I18nModule.forRoot({
      fallbackLanguage: 'en',
      loaderOptions: {
        path: path.join(__dirname, '/i18n/'),
        watch: false,   // <------ This flag
      },
      resolvers: [new QueryResolver(['locale']), AcceptLanguageResolver],
    }),

And today we had again this issue, and resolved it by disabling this flag too in nest-cli.json :

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "assets": [{ "include": "i18n/**/*", "watchAssets": false }] <----- watchAssets flag
  }
}