-
Notifications
You must be signed in to change notification settings - Fork 309
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]: [ng13] - Cannot find module '@angular/common/locales/xxx' #1147
Comments
Our default resolver won't solve all cases I believe. You would need to use @alan-agius4 do you have any other suggestions? |
@ahnpnl, let me get back to you on this tomorrow. |
Should have added this test is working fine on ng@12 / jest-preset-angular@9, with this require('jest-preset-angular/ngcc-jest-processor');
module.exports = {
preset: 'jest-preset-angular',
// ...
} I only changed to these suggested properties while troubleshooting but I don't think it makes a difference. module.exports = {
resolver: "jest-preset-angular/build/resolvers/ng-jest-resolver.js",
transformIgnorePatterns: ["node_modules/(?!@angular)"],
transform: {
"^.+\\.(ts|js|mjs|html|svg)$": "jest-preset-angular",
},
testEnvironment: "jsdom",
// ...
} |
The workaround for your problem is
Angular 13 ships Angular packages with ESM format, which is not the same as Angular 12. The guide in documentation might need to update though :) We did add a resolver but it won't work for all cases. In this case, deep import in |
Thanks @ahnpnl, this solves my issue ! |
Thanks for the suggestion. I will add it to the documentation. In the meantime, I would like to wait to see if Angular team has any other suggestions since this is related to Angular 13 specific package format. |
I did take a look at this and it appears that the problem is that @ahnpnl, this should be added in the preset jest-preset-angular/presets/index.js Line 12 in 1e7dbf8
@shajz, since you are not using the preset recommended settings via module.exports = {
resolver: "jest-preset-angular/build/resolvers/ng-jest-resolver.js",
transformIgnorePatterns: ["node_modules/(?!@angular)"],
+ moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
- moduleFileExtensions: ['ts', 'html', 'js', 'json'], |
Thanks a lot @alan-agius4!!! I will add it. |
Thanks @alan-agius4 and @ahnpnl, just tested out |
I face a similar error when trying to use
I read the guide about this issue with deep path imports and checked your workaround as well, Therefore, I am a bit lost on how to fix this problem. |
I manage to make it work by adding this in jest config file:
you can find an example in this repo https://github.com/cedricduffournet/test-ngrx-error |
Thanks @cedricduffournet, it works perfectly! |
Version
11.0.0-rc2
Steps to reproduce
npm ci
npm test
Expected behavior
I expect locales to be registered correctly from test files
Actual behavior
Additional context
Upgraded to Angular 13, followed instructions for jest-preset-angular@11 (using specified
resolver
,transformIgnorePatterns
,transform
; was usingpreset: jest-preset-angular
before)Environment
The text was updated successfully, but these errors were encountered: