TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Flat Tree Dependency Resolution in Npm v3

113 pointsby funerrover 9 years ago

15 comments

kylecordesover 9 years ago
I understand that this is a hairy, messy problem they are solving, and that they traded off one aspect of the problem for another (Install order dependency! as a new &quot;feature&quot; in 2015!).<p>But I wish they had aimed higher. The better goal would be that the entire state of the node modules directory is a pure function of the contents of the package.json file plus the platform details (compiler used for native modules).<p>While they&#x27;re at it, the ecosystem could be improved considerably if there was some sort of obvious &quot;penalty&quot; applied to any package that compiles native code, because such things cause considerable extra trouble for Windows users. A visible penalty, transitively carried up the dependency tree, would discourage use of such modules with native code; projects would use them (depend on them) only if absolutely necessary instead of accidentally, all over, all the time.
评论 #10818446 未加载
评论 #10818613 未加载
评论 #10818402 未加载
评论 #10818663 未加载
评论 #10818430 未加载
评论 #10818734 未加载
tlrobinsonover 9 years ago
<i>&quot;dependency resolution depends on install order&quot;</i><p>Does this sound insane to anyone else?<p>EDIT: I understand not wanting to modify node&#x27;s `require` semantics, but this is an unacceptable sacrifice of consistency for efficiency. Surely it would have been possible for an `npm install --save x` to put the `node_modules` directory in a state identical to `npm install --save x &amp;&amp; rm -rf node_modules &amp;&amp; npm install`. It might take a little longer to shuffle some directories around, but certainly not longer than a full `npm install`.
评论 #10821281 未加载
评论 #10820171 未加载
评论 #10819848 未加载
theGimpover 9 years ago
That&#x27;s a great improvement over the old behavior, but I&#x27;m wondering why the team didn&#x27;t go a different route.<p>Why not always store packages at the top level, and create a directory for each version that&#x27;s required?<p>For example: directory &quot;A&quot; contains two subdirectories: &quot;v0.1.0&quot; and &quot;v0.1.1&quot;
评论 #10818520 未加载
评论 #10818507 未加载
vecover 9 years ago
So, assuming I have two libraries, A and B, that both require the same version of library C, do those libraries still get their own separate in-memory copies of C, or do they share a singleton?<p>It&#x27;s terrible practice, but it&#x27;s not unheard of for an NPM module to monkey patch its dependencies, since before this the library could assume it had sole ownership of its whole subtree.
评论 #10818511 未加载
评论 #10818427 未加载
vfc1over 9 years ago
Jspm solves this by installing the module in a directory appending the package version. There is no maximally flat tree, the tree is 100% flat. At most there are several versions of the same package side by side, but no nesting.<p>It even supports circular dependencies.
评论 #10819994 未加载
评论 #10819835 未加载
amasadover 9 years ago
This is good news for client side bundlers like Webpack and Browserify -- where size really matters -- they don&#x27;t have to end up with multiple copies of the same module.<p>I would also assume for very large apps it may improve startup time because you don&#x27;t have to initialize and retain multiple copies of the same module.
评论 #10818445 未加载
评论 #10818832 未加载
评论 #10818415 未加载
ag_dubsover 9 years ago
as the person who wrote these docs-- if you have questions or things you&#x27;d like to see addressed, i&#x27;d really love if you filed issues on the repo. <a href="https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;docs&#x2F;issues" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;docs&#x2F;issues</a>
ruffreyover 9 years ago
If this works it might reduce the slug size of a built node app by a lot of a little.<p>Though, if there are problems, I wonder - can the flat dep resolution be disabled using some CLI flag? Or when installing deps, or in .npmrc, or during a shrinkwrap?
tolmaskyover 9 years ago
I just filed a bug: <a href="https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;npm&#x2F;issues&#x2F;10999" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;npm&#x2F;issues&#x2F;10999</a><p>I guess I&#x27;m not sure what level of non-determinism they expect, but on this page: <a href="https:&#x2F;&#x2F;docs.npmjs.com&#x2F;how-npm-works&#x2F;npm3-nondet" rel="nofollow">https:&#x2F;&#x2F;docs.npmjs.com&#x2F;how-npm-works&#x2F;npm3-nondet</a> it appears to make the claim that the only effect is on tree structure, not the actual versions of packages that are picked up. And in fact in their example this IS the case. I think this is fine btw.<p>However, I have found edge cases where install order actually changes the versions of packages that are picked up, and in ways that make it very very difficult to work around (basically you will be forced to manually edit a shrink-wrap file -- so it is necessarily on the end user not the package writer).<p>Basically, if any package lists and absolute dependency (vs a semver range), it will affect ALL the packages alphabetically later than it and FORCE them to take the same dependency.
bhoustonover 9 years ago
I do not understand why they just didn&#x27;t have a two level directory structure:<p>node_modules&#x2F;[module_name]&#x2F;[version]<p>Then it would be flat and support multiple versions of the same module in a way that is completely deterministic and also fully deduplicated.<p>This new system is unnecessarily complex.
评论 #10820791 未加载
评论 #10821936 未加载
hoodoofover 9 years ago
Sorry to be negative but one of the things that I hate more than anything in my software development work is typing &quot;npm install blah&quot; and almost always being hit with wave after wave of errors typically related to dependencies. I don&#x27;t know why it happens and I don&#x27;t care I just wish they&#x27;d fix it. So many, many errors.<p>Go on, try installing X packages at random using npm - did they install cleanly?<p>The baseline outcome for using a package installer should not be reams of errors, it should be a cleanly installed package. Installing packages works fine with other language ecosystems, why not with npm?
评论 #10819818 未加载
shillover 9 years ago
This will help Windows users who have filesystem and zip compression issues with deeply nested dependency trees.
评论 #10818387 未加载
brianbarkerover 9 years ago
V2&#x27;s deep nesting recently caused trouble for us at work. We had errors where our node_modules folder was too long for Windows, due to the deep folder structure. Updating to v3 resolved the problem. Hopefully other flaws being discussed here can be worked out as npm evolves.
justinsaccountover 9 years ago
Will this prevent node_modules&#x2F; from having 17 copies of the the same file in 17 different places?
评论 #10818330 未加载
z3t4over 9 years ago
I think they are trying to be too smart about it ... I rather waste several GB&#x27;s of HDD space then having my production crash <i>once</i> because of dependencies.