-
-
Notifications
You must be signed in to change notification settings - Fork 35.1k
Description
📗 API Reference Docs Problem
- Version: ✍️
Latest (and prior)
- Platform: ✍️
n/a
- Subsystem: ✍️
'module'
Location
see below
Description
Concise explanation of the problem
✍️
for reference:
https://nodejs.org/dist/latest-v17.x/docs/api/module.html#modulecreaterequirefilename
the documentation for createRequire for the filename parameter states:
Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string.
which is not really descriptive about what is expected and how it influences the behavior.
from an older version of the [now removed] createRequireFromPath function the docs state:
https://nodejs.org/dist/v12.2.0/docs/api/modules.html#modules_module_createrequirefrompath_filename
Filename to be used to construct the relative require function.
I assume it puts the [created] require function in the relative path (directory) of the specified filename parameter. Not really sure how I would express this in a meaningful way. 🤔
I think it would also make sense to add a little explainer why such a thing exists: require does not exist in an es module context vs. commonjs can also be imported with es module syntax, although the expectations and behavior in both are likely very different as well.
the docs could also state that createRequire is less useful in a commonjs context, e.g. const { createRequire: _require = require('module')
- I would like to work on this issue and submit a pull request.