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
Bug(TranslocoTestingModule): Cannot find module 'flat' #714
Comments
We have the same issue after upgrading to Transloco Version 5, an upgrade to version 6 does not help. |
Personally, I have no issue with Transloco v5, only with v6 |
Have this issue on a new project using Transloco 6.0.0 and Jest 29.4.1 |
Looks like a duplicate of #704. I have minimal nx workspace setup with reproduction of this issue:
Update: |
Same issue for us. I managed to make Jest work with Transloco v6 by switching option |
the
|
What ended up working for us was changing
Tests run a bit slower (cache enabled), from about 30s went up to 40s. |
Thanks for your replies! @jkremlacek that Jest config ended up working for me: I updated the ng16 sandbox repo provided with this issue https://github.com/vankeer/transloco-sandbox/blob/bugfix/714-cannot-find-module-flat/jest.config.ts Downgrading to 5.0.7 instead of 5.0.10 also fixes the issue, so the issue is clearly related to the last changes in those Transloco patch versions. When I run Jest with |
When should we expect fix? |
Indeed downgrading to 5.0.7 works for me as well |
@dmytro-afonin When the war in my country is over. This is more of a documentation issue. flat is used by Transloco at runtime so it makes sense to use ESM instead of commonjs as it was up until now ( there was no ESM distribution ). As I wrote (and you can see both on the versions themselves and on the Transloco changelog) versions 5.0.8-10 are deprecated as they contain the breaking change of upgrading flat to ESM. I invite all of you to find and share the best solution for using ESM on jest as this change should stay IMO (security reasons, ESM on browser). You are welcome to share thoughts, though please note that I won't be available to respond anytime soon. |
Perhaps a simpler solution could be mapping the
|
This solution works fine for me thank you ! |
Been trying all of these solutions, does not seem to work on a pnpm based nx monorepo. |
@kevintyj Transloco v5.0.7 should have the cjs version of flat and ng 16 support |
Thank you so much for the response. We would love to stay on ng17, still looking for ways to fix this, but it's quite a big of a bottleneck for our pipeline at the moment. We are going to try to manually transpile ESM flat dependency to CJS somehow in the build step reliably, but it seems to spit out other errors. |
@kevintyj I'll clarify, it supports v16 and above (at least it should) so you can keep using angular v17. Did you encounter any issues? |
Have this issue on a project with angular v17, Transloco 6.0.1 and Jest 29.5.10 |
@guzmanoj I am now using the following combination: All is now working by adding the following to
|
As mentioned in #704 already:
works just fine for me using version |
@jjs98 didn't work for me, still have the following error
|
Would anyone want to add a documentation section on the possible solutions for the jest/ESM issues addressed here? |
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
No
Current behavior
This occurs:
Those specific Jest tests importing the TranslocoTestingModule will fail with the error:
Cannot find module 'flat' from 'node_modules/@ngneat/transloco/fesm2022/ngneat-transloco.mjs'
This does not occur when using the experimental @angular-devkit/build-angular:jest builder but this is not an option for this specific project, because that experimental builder doesn't support code coverage generation properly.
Expected behavior
Jest tests should work when importing the TranslocoTestingModule
Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.
https://github.com/vankeer/transloco-sandbox/tree/transloco-testing-bug
Transloco Config
Browser
Additional context
Explicitly installing the
flat
module does not help (but should not be necessary anyway).Run
npx jest
ornpx ng test
in the linked demo repo.Side-note, but commit 290920b645b94845ff0265451e2af560b083b98d shows a working version using the experimental @angular-devkit builder for Jest.
Related issues (that do not provide a solution for this specific problem as far as I can tell):
I would like to make a pull request for this bug
No
The text was updated successfully, but these errors were encountered: