Skip to content
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

cannot find module 'ngx-mask' when running jest on angular 13 #962

Closed
RogierKonings opened this issue Dec 22, 2021 · 10 comments
Closed

cannot find module 'ngx-mask' when running jest on angular 13 #962

RogierKonings opened this issue Dec 22, 2021 · 10 comments

Comments

@RogierKonings
Copy link

RogierKonings commented Dec 22, 2021

🐞 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. (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"

@manuelmeister
Copy link
Contributor

I can reproduce this. The generated package looks different:

Comparison
ngx-mask@12ngx-mask@13
.
├── LICENSE
├── README.md
├── bundles
│   ├── ngx-mask.umd.js
│   └── ngx-mask.umd.js.map
├── esm2015
│   ├── index.js
│   ├── lib
│   │   ├── config.js
│   │   ├── custom-keyboard-event.js
│   │   ├── mask-applier.service.js
│   │   ├── mask.directive.js
│   │   ├── mask.pipe.js
│   │   ├── mask.service.js
│   │   └── ngx-mask.module.js
│   └── ngx-mask.js
├── fesm2015
│   ├── ngx-mask.js
│   └── ngx-mask.js.map
├── index.d.ts
├── lib
│   ├── config.d.ts
│   ├── custom-keyboard-event.d.ts
│   ├── mask-applier.service.d.ts
│   ├── mask.directive.d.ts
│   ├── mask.pipe.d.ts
│   ├── mask.service.d.ts
│   └── ngx-mask.module.d.ts
├── ngx-mask.d.ts
├── ngx-mask.metadata.json
└── package.json

5 directories, 26 files
.
├── LICENSE
├── README.md
├── esm2020
│   ├── index.mjs
│   ├── lib
│   │   ├── config.mjs
│   │   ├── custom-keyboard-event.mjs
│   │   ├── mask-applier.service.mjs
│   │   ├── mask.directive.mjs
│   │   ├── mask.pipe.mjs
│   │   ├── mask.service.mjs
│   │   └── ngx-mask.module.mjs
│   └── ngx-mask.mjs
├── fesm2015
│   ├── ngx-mask.mjs
│   └── ngx-mask.mjs.map
├── fesm2020
│   ├── ngx-mask.mjs
│   └── ngx-mask.mjs.map
├── index.d.ts
├── lib
│   ├── config.d.ts
│   ├── custom-keyboard-event.d.ts
│   ├── mask-applier.service.d.ts
│   ├── mask.directive.d.ts
│   ├── mask.pipe.d.ts
│   ├── mask.service.d.ts
│   └── ngx-mask.module.d.ts
├── ngx-mask.d.ts
└── package.json

5 directories, 25 files

@kievsash
Copy link

I had issue with running jest with ngx-mask ver 13 on Angular 12.1 (I think bc it doesnt contain .js files but .mjs).
Rolling back to ngx-mask 12 solved the issue.

@JosephBarkate
Copy link

Seeing the same issue with Angular 13.0.1 and NGX-Mask 13.0.1

@guilhermetod
Copy link

The issue is actually the absence of the file indicated in the main field. 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.js

moduleNameMapper: {
  // ...
  'ngx-mask': '<rootDir>/node_modules/ngx-mask/fesm2015/ngx-mask.mjs',
},

Or alternatively, this to your tsconfig.spec.json

"paths": {
  "ngx-mask": ["node_modules/ngx-mask/fesm2015/ngx-mask.mjs"]
}

@guilhermetod
Copy link

For reference: ngrx/platform#3248

@NepipenkoIgor
Copy link
Collaborator

@guilhermetod Thank you for explanation

@kevinmallinsonflynn
Copy link

@NepipenkoIgor

This should not be closed IMO as the issue still occurs.

@NepipenkoIgor NepipenkoIgor reopened this Jun 6, 2022
@thayna-oliveira
Copy link

Same error here! 😢

@NepipenkoIgor
Copy link
Collaborator

Hi @RogierKonings @manuelmeister @kievsash @JosephBarkate @kevinmallinsonflynn @RogierKonings @thayna-oliveira Hi All. Thank you that using ngx-mask package. Yes it was couple mistakes with updating to ng13 . Issues was around paths and build config angular package system . Please try version >=14.2.1 . Everything should works as expected

@e4nie
Copy link

e4nie commented Feb 6, 2023

It works when you down-grade the version , i install the version 12npm install ngx-mask@12, and it works and resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants