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

[Bug]: require.resolve.paths cannot reach global path in the scope of jest #13439

Closed
lvqq opened this issue Oct 14, 2022 · 7 comments · Fixed by #13633
Closed

[Bug]: require.resolve.paths cannot reach global path in the scope of jest #13439

lvqq opened this issue Oct 14, 2022 · 7 comments · Fixed by #13633

Comments

@lvqq
Copy link
Contributor

lvqq commented Oct 14, 2022

Version

v29.1.2, the newest

Steps to reproduce

Minimal reproduction: https://github.com/lvqq/jest-require-resolve-paths

Steps:

  1. npm install
  2. npm test

Expected behavior

require.resolve.paths is consistent in jest and in node

Actual behavior

In node, require.resolve.paths('npm') returns:

[
  'D:\\RD\\project\\jest-require-resolve-paths\\node_modules',
  'D:\\RD\\project\\node_modules',
  'D:\\RD\\node_modules',
  'D:\\node_modules',
  'C:\\Users\\chlorine\\.node_modules',
  'C:\\Users\\chlorine\\.node_libraries',
  'D:\\RD\\nodejs\\lib\\node'
]

In the scope of jest, require.resolve.paths('npm') returns:

[
  'D:\\RD\\project\\jest-require-resolve-paths\\node_modules',
  'D:\\RD\\project\\node_modules',
  'D:\\RD\\node_modules',
  'D:\\node_modules'
]

The global paths are missing.

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
  Binaries:
    Node: 16.17.0 - D:\RD\nodejs\node.EXE
    Yarn: 1.22.10 - D:\RD\nodejs\node_global\node_modules\yarn\bin\yarn.CMD    npm: 8.15.0 - D:\RD\nodejs\npm.CMD
  npmPackages:
    jest: ^29.1.2 => 29.1.2
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 13, 2022
@lvqq
Copy link
Contributor Author

lvqq commented Nov 13, 2022

Mark

@jeysal
Copy link
Contributor

jeysal commented Nov 13, 2022

Confirmed. We fall back to resolving using require.resolve if our custom resolver does not find anything, so we should probably also append the real require.resolve.paths() from outside the Jest runtime to the require.resolve.paths() that we return to code in the runtime. PR welcome!

@lvqq
Copy link
Contributor Author

lvqq commented Nov 14, 2022

Thanks! I'd like to work on implementing it

@jeysal
Copy link
Contributor

jeysal commented Nov 14, 2022

Cool! In case this helps your get started: require and require.resolve and require.resolve.paths are implemented by jest-runtime, which then does some calls to jest-resolve which knows things like how to look up in the directory tree to look for node_modules etc.

@github-actions
Copy link

github-actions bot commented Jan 2, 2023

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 Jan 2, 2023
@SimenB
Copy link
Member

SimenB commented Jan 24, 2023

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

Successfully merging a pull request may close this issue.

3 participants