Skip to content

Cannot find module, because of infinite loop in jest-resolver #5088

@eaviles

Description

@eaviles

After experiencing a lot of intermittent errors like this one:

Cannot find module 'X' from 'Y'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)

I looked at the resolver code and realized there was an infinite loop that would eventually cause this error to appear. We have a couple of NPM modules that in their package.json file have the main entry point defined as:

    "main": "."

Because of this, the following line of code would make a path resolve into the same path.

https://github.com/facebook/jest/blob/78477eb526f2ebd901f3daa0abef0e8cc591bfb8/packages/jest-resolve/src/default_resolver.js#L133

This will call the tryResolve function with the same path, that will go on and on until the maximum call stack is reached. I tried changing pkgmain to "index.js" whenever it was defined as "." and the issue went away.

Wondering if there could be other differences in how Node resolution of modules works vs. how the Jest resolver works. Let me know if my team can contribute to fix this. Looking forward to help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions