Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: require.resolve with empty paths option does not locate absolute paths #11927

@ekelen

Description

@ekelen

Version

27.2.4

Steps to reproduce

See repo README at https://github.com/ekelen/jest-require-resolve-empty-paths-array

OR:

  1. Clone reproduction repo linked above and change current directory to repo root.
  2. Run cp test.js /tmp && node -p "require.resolve('/tmp/test', { paths: [] } )" (returns path of tmp/test.js at filesystem root).
  3. Run yarn install.
  4. Run yarn test.

Expected behavior

No error should be thrown when require.resolve is called with a valid module at user's filesystem root and an empty paths array option.

The output of require.resolve("/tmp/test", { paths: ["/"] }) should match the output of require.resolve("/tmp/test", { paths: [] }).

Actual behavior

If provided an empty paths array, ModuleNotFoundError is thrown: Cannot resolve module '/tmp/test' from paths [''] from <repo_root>/test.js.

Additional context

Appears to be a parallel issue to #9502.

Environment

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 16.8.0 - ~/.volta/tools/image/node/16.8.0/bin/node
    Yarn: 1.22.15 - ~/.volta/tools/image/yarn/1.22.15/bin/yarn
    npm: 7.21.0 - ~/.volta/tools/image/node/16.8.0/bin/npm
  npmPackages:
    jest: 27.2.4 => 27.2.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions