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, because of infinite loop in jest-resolver #5088

Closed
eaviles opened this issue Dec 15, 2017 · 5 comments
Closed

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

eaviles opened this issue Dec 15, 2017 · 5 comments

Comments

@eaviles
Copy link

eaviles commented Dec 15, 2017

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.

@SimenB
Copy link
Member

SimenB commented Dec 16, 2017

Would love a PR fixing main: "." 🙂

Wondering if there could be other differences in how Node resolution of modules works vs. how the Jest resolver works.

Hopefully not. You can take a look at node's resolution to see if there are any holes? https://github.com/nodejs/node/blob/604578f47ea360980110e2cd7d4a636f9942b1f0/lib/module.js#L151-L153

@eaviles
Copy link
Author

eaviles commented Dec 21, 2017

Thanks @SimenB, we will send a PR soon!

@kenzable
Copy link
Contributor

@SimenB Opened PR

@cpojer cpojer closed this as completed Jan 19, 2018
@mtlewis
Copy link
Contributor

mtlewis commented Apr 11, 2018

Looks like modules with a main entry of "./" (like co-request) are also susceptible to this issue. I'll open a separate issue for this.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants