-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
How does require.resolve work? #8526
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
Comments
Can you give an example, preferably in runnable code, that demonstrates exactly what you want to happen? Also, keep in mind that the chances of landing a PR that changes the module system behavior is extremely small. |
Be careful when attempting to resolve paths/files in the parent path of current package. For example, current package could be All this assuming I understood correctly your intentions about "resolving the root project's package name". As @cjihrig suggested, runnable code would demonstrate your intentions best. |
@cjihrig Here's basically what I want to work: mkdir cool-app
cd cool-app
npm init -y
echo "module.exports = { name: 'chet' }" > defs.js
echo "console.log('hello' + require('cool-app/defs').name)" > index.js
node index.js
> hello chet basically |
So you basicly want virtual version of: ln -sf .. node_modules/<root package name> Tested this and symlink actually works and allows If this is implemented in module.js resolver, I'm bit worried about (theoretically) possible name collision with npm installed packages. |
I'm not sure that making this change is worth the risk, especially when you can already use relative paths. I'll leave this open in case another collaborator is willing to champion this. |
-1 from me. The module system is locked. |
-1 from me too. Locked module API and high risk for hard-to-debug userland regressions if implemented. |
-1 from me. |
I think there are enough -1s to warrant closing this. Thanks anyway though! |
I'd like to submit a PR that resolves the root project's package name so that you can use absolute require paths. However, I'm finding it very hard to figured out how this bit of code works:
https://github.com/nodejs/node/blob/7b73f559029a10474b74a83bfb1117ab512785d4/lib/module.js
Seems like it should be a one-liner somewhere. I just need to add the base project as one of the "paths" to search. Any ideas where that might be?
I'm thinking its in here.
node/lib/module.js
Line 304 in 7b73f55
Something like
paths.push(path.dirname(parent.id))
.The text was updated successfully, but these errors were encountered: