-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
NODE_PATH documentation appears to be incorrect #38128
Comments
@nodejs/modules |
Yes, this should be changed in docs. You can see the "global directories" added in https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L677 . NOTE: global directories are only in CommonJS and are strictly not supported by ESM |
NODE_PATH is also widely discouraged in the ecosystem, and many tools don’t support it at all, including resolve. I’d suggest not adding it to esbuild. |
Fixes: nodejs#38128 PR-URL: nodejs#38837 Reviewed-By: Guy Bedford <guybedford@gmail.com>
Context: evanw/esbuild#1117
I'm trying to replicate node's module resolution algorithm into esbuild, which is a JavaScript bundler that I'm building. I based my implementation on node's documented algorithm here:
doc/api/modules.md
. However, it seems like the documented algorithm is different than how node actually works. Specifically this part:This reads to me like the iteration order is
for each DIR in [GLOBAL_FOLDERS] + ["node_modules" folders]
soNODE_PATH
takes precedence over all other folders. However, node actually behaves as if the iteration order is insteadfor each DIR in ["node_modules" folders] + [GLOBAL_FOLDERS]
. Specifically this part inlib/internal/modules/cjs/loader.js
):This is essentially
_nodeModulePaths().concat(nodePath.split(':'))
so all other folders take precedence overNODE_PATH
.Assuming the documentation is just incorrect, can the documentation be changed to reflect how node actually works? Or if not, is node's implementation of the algorithm incorrect and node itself should be fixed to match the algorithm?
The text was updated successfully, but these errors were encountered: