-
Notifications
You must be signed in to change notification settings - Fork 280
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
Differentiate between core modules and userland modules #562
Comments
No, it's special-cased. Built-in modules always take precedence.
cluster? Honesty compels me to admit that the npm module came first. |
Ok :) thanks is there any good solution to accurately sourcing a core module instead of the NPM module? Process.binding(X) or something? |
@bnoordhuis actually, according to my testing, the core module loaded first I just have this script: const cluster = require('cluster'); then I simply modified the index.js file in node_modules/cluster/index.js like so: didn't get the log statement, so it appears core module loaded first I will ask the cluster module folks about what's going on and report back... |
@bnoordhuis just tested again, both devDependency or regular dependency, core module gets loaded first for me, I am on node.js version 6.9.5 |
Yes, that's what I said: built-in modules always take precedence. |
Well you said: "Honesty compels me to admit that the npm module came first." That statement totally confused me, making me think that the userland module came first :) |
@bnoordhuis my guess is that you can require the cluster userland module with |
yep that worked, just FYI, crazytown |
@bnoordhuis means that the npm package was published first, but then a built-in module was created with the same name.
So even though the npm module was created first, it won't be loaded if you |
No npm module should have the same name as a node core module. No node core module should be created that shadows the name of an npm module, either, but that's ancient history by now. It seems to me that 'cluster' is abandoned: https://github.com/LearnBoost/cluster/commits/master, if it was still active, I suspect they would publish it under a new name. |
@sam-github yeah I didn't realize that 'cluster' was the only name-clash, I thought there were others. In any case, like I said, if there were ever a name clash again, as it stands now, you can just add a slash and the NPM module would be required. require('cluster/'); although that's getting into some messier territory. |
It's not the only clash, there are some others, but it doesn't really matter because unless you try and explicitly load it, the built-ins will be loaded first. |
This regards Node versions 4.0.0 <--> latest
TMK there are a few modules on NPM that have a name clash with core modules. To a large extent I think NPM has done the work of preventing this from happening, but I believe there is at least one or two core modules that name clash with NPM modules.
My guess is that if X is both a core module and NPM module, that the NPM module will get precedence given the way require works in Node.js?
My question is, assuming there is a name clash:
Unfortunately, I cannot remember the name of the core module clash, but I swear there is at least one if not several.
The text was updated successfully, but these errors were encountered: