Skip to content

require.resolve.paths(${built-in module id}) returns null #18230

Closed
@shinnn

Description

@shinnn
  • Version: v9.4.0
  • Platform: macOS 10.13.2

When require.resolve.paths() receives a Node.js built-in module ID, for example fs and http2, it doesn't return Array<string> but null.

$ node -p "require.resolve.paths('.');"
[ '/Users/shinnn/test',
  '/Users/shinnn/test/node_modules',
  '/Users/shinnn/node_modules',
  '/Users/node_modules',
  '/node_modules',
  '/Users/shinnn/.node_modules',
  '/Users/shinnn/.node_libraries',
  '/usr/local/Cellar/node/9.4.0/lib/node' ]

$ node -p "require.resolve.paths('fs');"
null

$ node -p "require.resolve.paths('http2');"
null

Is this an expected behavior? I'm OK with the current null returning behavior but we should inform this special case in the API document. Otherwise, if the original intent of #16397 is always retrieving Array<string> as currently documented, we should fix the bug.


For reference, require.resolve returns the ID itself when it takes one of the built-in module IDs.

$  node -p "require.resolve('fs');"
fs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions