镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

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

Activity

  1. cjihrig commented on Jan 18, 2018

    @cjihrig
    Contributor

    I think documenting null as a possible return value here is fine.

  2. added
    docIssues and PRs related to Node.js documentation.
    on Jan 18, 2018
  3. shinnn commented on Jan 25, 2018

    @shinnn
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions