Skip to content

[gulp-core-build] Jest Less moduleDirectories circular lookup  #1778

@sadsa

Description

@sadsa

Please prefix the issue title with the project name i.e. [rush], [api-extractor] etc.

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.

In my company, we are using @microsoft/gulp-core-build to create our own gulp build chain specific to our needs. An issue came about when adding a library called ``fetch-mock (a popular fetch mocking library for unit tests) to our dependencies. For some reason, when running npx jest --config=config/jest/jest.config.json all the tests passed and there were no issues. However, when running with `rushx build` which in turn runs `gulp test --clean`, I got an error showing that the `require(debug)` statements internal to `fetch-mock` was returning an empty object `{}`. After some investigation, I saw that node will return `{}` if there it resolves to a cyclical path (i.e. it references itself).

What is the expected behavior?

I fixed the issue by adding "moduleDirectories": ["node_modules"] to the jest.config.json file.

{
  "rootDir": "../../",
  "setupFiles": ["./config/jest/setupJest.js"],
  "globals": {
    "ts-jest": {
      "tsConfig": "config/jest/tsconfig.json",
      "packageJson": "package.json"
    }
  },
  "moduleFileExtensions": ["js"],
  "moduleDirectories": ["node_modules"],
  "moduleNameMapper": {
    "ts-jest": "<rootDir>/node_modules/ts-jest/index.js"
  },
  "transform": {
    "^.+\\.(ts|tsx)$": "ts-jest"
  },
  "testURL": "http://localhost/"
}

By default https://github.com/microsoft/rushstack/blob/master/core-build/gulp-core-build/src/tasks/JestTask.ts sets this property to ["node_modules", "lib"]. So.... it was looking for a module called debug in lib before checking node_modules and found itself. Thus, resolving to itself and causing the error.

I suggest discussing why "lib" is included in this list by default for LessTask.ts.

I hope this helps someone one day.

If this is a bug, please provide the tool version, Node.js version, and OS.

  • Tool: RushJS
  • Tool Version: 5.20.0
  • Node Version: 12.16.1
    • Is this a LTS version?
    • Have you tested on a LTS version?
  • OS:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions