cannot find module 'ngx-mask' when running jest on angular 13
See original GitHub issueπ bug report
Is this a regression?
Yes, the previous version in which this bug was not present was: ....The bug does not appear in version <=12, where the unit test succeeds but throws a TypeError
Description
A clear and concise description of the problem...π¬ Minimal Reproduction
https://stackblitz.com/...Run jest on a unit-test that imports NgxMaskModule.
The test will fail and show a stacktrace
π₯ Exception or Error
Cannot find module 'ngx-mask' from 'app/my-component.spec.ts'
> 1 | import { NgxMaskModule } from 'ngx-mask';
| ^
2 | import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 | import { HttpClientTestingModule } from '@angular/common/http/testing';
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (app/my-component.spec.ts:1:1)
π Your Environment
Angular Version:
Angular CLI: 13.1.2
Node: 16.13.0
Package Manager: npm 8.1.0
OS: darwin x64
Angular: 13.1.1
... animations, cdk, common, compiler-cli, core, forms
... language-service, localize, material, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1301.2
@angular-devkit/build-angular 13.1.2
@angular-devkit/core 13.1.2
@angular-devkit/schematics 13.1.2
@angular/cli 13.1.2
@angular/compiler 13.0.2
@angular/flex-layout 13.0.0-beta.36
@schematics/angular 13.1.2
rxjs 7.4.0
typescript 4.4.3
Anything else relevant?
βjestβ: β27.4.5β
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (1 by maintainers)
Top Results From Across the Web
ngx-mask - npm
Start using ngx-mask in your project by running `npm i ngx-mask`. ... For version ngx-mask < 15.0.0 Import ngx-mask module in Angular app....
Read more >angular13 - Angular 13 upgrade - JEST issue - Stack Overflow
I am upgrading my angular app from v12 to v13. It gets compiled without issues. Even ng build works fine. But the unit...
Read more >cannot find module '@angular/core/testing' from ... - You.com
So I was searching online for quite sometime then I came across this solution, hope it works for you as well. In the...
Read more >Angular >=13 | jest-preset-angular - GitHub Pages
ES Modules support is new and may encounter issues. See example-app-v13 for an example with tests that run using ESM, and using ESM...
Read more >ng serve Cannot find module '@angular/compiler' Code Example
npm i --save-dev @angular/compiler-cli.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The issue is actually the absence of the file indicated in the
mainfield. Angular 13 probably doesnβt generate βumd.jsβ files anymore, so this file doesnβt exist.Iβm unsure if this is a problem with this library pointing to that file or if this should be something that
jest-preset-angularβs resolver should be fixing (since angularβs cli knows how to find the correct file and bundle it).Anyways, workaround for now is to add the following to
jest.config.jsOr alternatively, this to your
tsconfig.spec.jsonSame error here! π’