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

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

Closed
shinnn opened this issue Jan 18, 2018 · 2 comments
Closed

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

shinnn opened this issue Jan 18, 2018 · 2 comments
Labels
doc Issues and PRs related to the documentations.

Comments

@shinnn
Copy link
Contributor

shinnn commented Jan 18, 2018

  • 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
@cjihrig
Copy link
Contributor

cjihrig commented Jan 18, 2018

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

@cjihrig cjihrig added the doc Issues and PRs related to the documentations. label Jan 18, 2018
nephross added a commit to nephross/node that referenced this issue Jan 24, 2018
Update documentation of modules.md for require.resolve.paths()
to include the possibillity of null as a return value if
the request string given matches a core module name.

Fixes: nodejs#18230
@shinnn
Copy link
Contributor Author

shinnn commented Jan 25, 2018

@cjihrig @jasnell @nephross @vsemozhetbyt Thanks.

evanlucas pushed a commit that referenced this issue Jan 30, 2018
Update documentation of modules.md for require.resolve.paths()
to include the possibillity of null as a return value if
the request string given matches a core module name.

PR-URL: #18350
Fixes: #18230
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 27, 2018
Update documentation of modules.md for require.resolve.paths()
to include the possibillity of null as a return value if
the request string given matches a core module name.

PR-URL: #18350
Fixes: #18230
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
Update documentation of modules.md for require.resolve.paths()
to include the possibillity of null as a return value if
the request string given matches a core module name.

PR-URL: nodejs#18350
Fixes: nodejs#18230
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants