You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is really a nestjs-i18n problem, it may very well be an Nx or jest or just nest, but I have to ask somewhere, so I hope asking here is okay.
I'm having problems getting the loader to find my i18n directory when running tests. I'm using Nx monorepo, and the relevant part of my directory structure is this:
When I run the app with "nx serve api" everything works, I've set up webpack to copy the i18n folder when I build the application, so all is good there. The problem is when I run tests with nx test api-e2e. I then get this error:
[Nest] 53798-02/28/2024, 11:29:29 AM ERROR [I18nService] parsing translation error
[Nest] 53798-02/28/2024, 11:29:29 AM ERROR [I18nService] Error: ENOENT: no such file or directory, stat '/home/roy/projects/myproject/apps/api/src/app/i18n/'
[Nest] 53798-02/28/2024, 11:29:29 AM ERROR [I18nService] parsing translation error
[Nest] 53798-02/28/2024, 11:29:29 AM ERROR [I18nService] Error: ENOENT: no such file or directory, scandir '/home/roy/projects/myproject/apps/api/src/app/i18n/'
Error: Jest: Got error running globalSetup -/home/roy/projects/myproject/apps/api-e2e/src/support/global-setup.ts, reason: ENOENT: no such file or directory, stat '/home/roy/projects/myproject/apps/api/src/app/i18n/'
Warning: command "jest" exited with non-zero status code
The i18n directory is located in /home/roy/projects/myproject/apps/api/src/i18n so that it can't find it in /home/roy/projects/myproject/apps/api/src/app/i18n makes sense. I assume the reason this happens, is that when I run nx serve api the folder is relative to app.module.ts which is started from main.ts in the parent directory. When running the tests however, I create the module using Test.createTestingModule from @nest/testing (this is done in api-e2e/src/support/global-setup.ts referenced in the error message), like this:
This apparently means that the working directory when I run the tests is /home/roy/projects/myproject/apps/api/src/app/ but when I run the app with nx serve api the working directory is /home/roy/projects/myproject/apps/api/src/.
I've been searching for a solution to this "everywhere", but I can't seem to find anything that works. That in itself is an issue because if nobody else is having this problem, then I must be doing something very wrong, and while that is entirely and firmly within the realm of possibility, I have no clue at all what that might be.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm not sure if this is really a nestjs-i18n problem, it may very well be an Nx or jest or just nest, but I have to ask somewhere, so I hope asking here is okay.
I'm having problems getting the loader to find my i18n directory when running tests. I'm using Nx monorepo, and the relevant part of my directory structure is this:
The module is loaded in
imports
inapp.module.ts
like this:When I run the app with "nx serve api" everything works, I've set up webpack to copy the i18n folder when I build the application, so all is good there. The problem is when I run tests with
nx test api-e2e
. I then get this error:The i18n directory is located in
/home/roy/projects/myproject/apps/api/src/i18n
so that it can't find it in/home/roy/projects/myproject/apps/api/src/app/i18n
makes sense. I assume the reason this happens, is that when I runnx serve api
the folder is relative toapp.module.ts
which is started frommain.ts
in the parent directory. When running the tests however, I create the module using Test.createTestingModule from@nest/testing
(this is done inapi-e2e/src/support/global-setup.ts
referenced in the error message), like this:This apparently means that the working directory when I run the tests is
/home/roy/projects/myproject/apps/api/src/app/
but when I run the app withnx serve api
the working directory is/home/roy/projects/myproject/apps/api/src/
.I've been searching for a solution to this "everywhere", but I can't seem to find anything that works. That in itself is an issue because if nobody else is having this problem, then I must be doing something very wrong, and while that is entirely and firmly within the realm of possibility, I have no clue at all what that might be.
Please help! :)
Beta Was this translation helpful? Give feedback.
All reactions