question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Haste module map error with @angular/cli libraries

See original GitHub issue

The library is generated by ng g library @itrulia/dates

    The name `@itrulia/dates` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:

      * `/home/talleane/Documents/@itrulia/dates/dist/itrulia/dates/package.json` (package)
      * `/home/talleane/Documents/@itrulia/dates/projects/itrulia/dates/package.json` (package)

dist is the generated output by ng build @itrulia/dates.

spec looks like this:

import {ReactiveFormsModule} from "@angular/forms";
import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {AppComponent} from "./app.component";
import {DatesModule} from "@itrulia/dates";

describe("AppComponent", () => {
    let component: AppComponent;
    let fixture: ComponentFixture<AppComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                AppComponent
            ],
            imports: [
                DatesModule,
                ReactiveFormsModule
            ]
        })
        .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(AppComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    it("should create", () => {
        expect(component).toBeTruthy();
    });
});

I have tried adding

modulePathIgnorePatterns: [
    "<rootDir>/projects"
  ],

This resulted in to Jest not being able to find @itrulia/dates.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

10reactions
acaillycommented, Feb 1, 2019

I fixed this issue by excluding dist dir in modulePathIgnorePatterns and mapping packages from @myscope to dist folder:

module.exports = {
  ... ,
  modulePathIgnorePatterns: [... , "<rootDir>/dist/"],
  ... ,
  moduleNameMapper: {
    "^@myscope/(.*)$": "<rootDir>/dist/myscope/$1"
  }
};
2reactions
ahnpnlcommented, Jul 3, 2018

No, actually in my opinion this is more like user specific requirements and Jest config can help you to handle that. The preset doesn’t take into account of it but only helps to setup base configuration to use Jest with an Angular project. It is similar to the case of configuring paths in tsconfig.json.

For example in my current work project, I did this in tsconfig.json:

"paths": {
      "@archive/*": ["app/archive/*"],
}

and in my Jest configuration I put this:

 "moduleNameMapper": {
      "^@archive/(.*)$": "<rootDir>/src/app/archive/$1",
}

This will help Jest to resolve the path correctly for the tests.

Can you try something similar like that ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: jest-haste-map: Haste module naming collision
The error you get indicates that you have two react-native dependencies. One in your main project, ...
Read more >
stryker-mutator/stryker - Gitter
When I run stryker run , I've got the following error message: ... jest --updateSnapshot jest-haste-map: Haste module naming collision: vehicle-dashboard ...
Read more >
haste module naming collision: the following files share their ...
I am getting the jest-haste-map issue after doing following steps: ... To Reproduce 1) amplify add function 2) function is created locally correctly...
Read more >
Javascript – the Haste module map in node.js - iTecNote
I have an error which says that : Unable to resolve module `util` from `/Users/canatac/RNProjects/<MyProject>/node_modules/<A_Module>/lib/Bot.js ...
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found