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.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeysalcommented, 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.

1reaction
lvqqcommented, Nov 14, 2022

Thanks! I’d like to work on implementing it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using eslint with typescript - Unable to resolve path to module
As soon as I compile the .ts file to a .js, the error goes away. However, since eslint is supposed to work with...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... Thresholds can be specified as global , as a glob, and as a...
Read more >
Configuring code coverage in Jest, the right way
Code coverage makes possible to spot untested paths in our code. It is an important metric for determining the health of a project....
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
If the module can not be found, a MODULE_NOT_FOUND error is thrown. require.resolve.paths(request) #. Added in: v8.9.0. request ...
Read more >
Requiring modules in Node.js: Everything you need to know
The require module, which appears to be available on the global scope — no need to ... If Node can't find find-me.js in...
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