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.

Yarn Plug'n'Play: Getting rid of node_modules

362 pointsby Coutoover 6 years ago

18 comments

wildpeaksover 6 years ago
Thing is, node_modules isn&#x27;t just thirdparty modules.<p>It&#x27;s just what the Node path resolution standard uses, which is also how Local Modules (the &quot;&#x2F;src&#x2F;node_modules&quot; structure) allows you to import other files with clean paths, without having to add a config in every tool of the toolchain, post-install symlinks, or any other non-crossplatform tricks. It just works because it&#x27;s literally what Node uses to resolve paths, and all build tools are based on Node, so when you stick to the standard resolution, you can add new tools to the toolchain without needing a bunch of configs for them to find your files. For example, it&#x27;s now also the default resolution in Typescript as well.<p>The only time &#x2F;src&#x2F;node_modules doesn&#x27;t work is when tool goes out of its way to break it, and wrongly assumes that node_modules can only ever be used for external thirdparty code (e.g. Jest).<p>So best of luck to make Node + NPM + Yarn to agree on a new path resolution syntax, but I hope we won&#x27;t end up with another tool-specific resolution that only works in Yarn.
评论 #17978535 未加载
arcatekover 6 years ago
I&#x27;m the author behind the proposal, feel free to ask me any question you might have!<p>As a personal note, I&#x27;m super excited and so grateful to have had the chance to work on this project - node_modules have been a longstanding thorn in the side of the Javascript ecosystem, and to finally have a chance to try something completely new is amazing.
评论 #17978858 未加载
评论 #17985754 未加载
评论 #17980654 未加载
评论 #17977933 未加载
评论 #17978006 未加载
评论 #17977917 未加载
评论 #17978103 未加载
评论 #17978485 未加载
评论 #17978835 未加载
jorangreefover 6 years ago
Removing `node_modules` would be fantastic, but not at the expense of native modules:<p>From the PDF:<p>&quot;On the long term we believe that post-install scripts are a problem by themselves (they still need an install step, and can lead to security issues), and we would suggest relying less on this feature in the future, possibly even deprecating it in the long term. While native modules have their usefulness, WebAssembly is becoming a more and more serious candidate for a portable bytecode as the months pass.&quot;<p>WebAssembly is not &quot;more and more a serious candidate&quot; to replace native modules.<p>The issue with post-install scripts needs a better long-term solution, but simply deprecating native modules is not it.
评论 #17978245 未加载
评论 #17978234 未加载
评论 #17978227 未加载
ohitsdomover 6 years ago
npm announced crux yesterday, seems focused on the same problems. Approach seems slightly different, although there aren&#x27;t as much technical details available for crux (unless someone has a better link):<p><a href="https:&#x2F;&#x2F;blog.npmjs.org&#x2F;post&#x2F;178027064160&#x2F;next-generation-package-management" rel="nofollow">https:&#x2F;&#x2F;blog.npmjs.org&#x2F;post&#x2F;178027064160&#x2F;next-generation-pac...</a><p>edit: found the repo, seems a bit behind yarn&#x27;s effort and not yet beta status. <a href="https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;crux" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;npm&#x2F;crux</a>
munificentover 6 years ago
This is effectively how pub, the package manager for Dart works. At version resolution time, we generate a manifest file that contains the local paths to every depended-upon package. Then, at compile&#x2F;load time, tools just use that file to locate packages.
gitgudover 6 years ago
Very cool, does this mean you can check in the dependency file to version control? Just like yarn.lock?<p>As much as I hate node_modules, there are times when I want to see how a library is implemented. Is there a way to have some libraries in node_modules? Say only the ones in listed in the package.json file
评论 #17978229 未加载
评论 #17978348 未加载
jannesover 6 years ago
I wish there was something I could do about reducing the contents of the node_modules folder instead of hiding the files somewhere else on disk.<p>It angers me how many dependencies very simple projects amass.
评论 #17978042 未加载
评论 #17978025 未加载
评论 #17979403 未加载
评论 #17978077 未加载
lucisferreover 6 years ago
All I really want is a consistent solution to the `..&#x2F;..&#x2F;..&#x2F;..` problem with local module resolutions.
评论 #17980751 未加载
评论 #17980508 未加载
评论 #17980080 未加载
i386over 6 years ago
Congratulations to the JavaScript community in reinventing the Maven local repository.<p>Hopefully yarn does a better job at validating dependencies than early Maven 1 and 2 did.
评论 #17984049 未加载
olingernover 6 years ago
I just came here to say this is great work, and congrats to the Yarn team for continually making package management more sane.
mstadeover 6 years ago
Nice work – what&#x27;s being done to make this the default behavior in node and deprecate node_modules proper, or is this forever destined to live in the awkward place of userland-but-not-really kind of territory?<p>People have already mentioned native modules. Install scripts are a nuisance, but exist for reasons. If you remove support for them – provided this project takes off, which I suppose it will because bandwagons – you risk people performing install-type tasks on first module load, potentially creating an even worse situation. Has this been considered as a risk?
评论 #17978709 未加载
lxeover 6 years ago
From what I understand: instead of cp -rf from offline cache, or ln -sf (which doesn&#x27;t work for a large percentage of packages due to node being node), they propose to use a custom resolver to tap into the cache directly.<p>This will also break for various packages due to fs.readFile* dependencies, gyp, and other things. If your dependency tree is 4k+ node modules, the &quot;vanilla&quot; yarn or npm resolution and reconciliation techniques are already so brittle, that changing them will undoubtedly break things.
cryptozeusover 6 years ago
Currently I use npm for angular projects. Before writing even hello world , I have to perform npm install on the project and install so many module to serve up small web app. This seems like we are going in the right direction, cant wait to try yarn as package manager.
ericintheloft2over 6 years ago
Novice question from someone from ruby land: would this work similar to bundler and Gemfile?
aijover 6 years ago
How does yarn pnp compare to nix? (node2nix)<p>I&#x27;ve been thinking about unifying our current ivy+yarn+bower setup, but haven&#x27;t yet gotten much past thinking about it...
specialistover 6 years ago
This is a compelling reason to switch:<p>From <a href="https:&#x2F;&#x2F;pnpm.js.org" rel="nofollow">https:&#x2F;&#x2F;pnpm.js.org</a><p>&quot;Efficient: One version of a package is saved only ever once on a disk. So you save dozens of gigabytes of disk space!&quot;<p>Without digging, I imagine this will be more like Maven&#x27;s cache.<p>NPM&#x27;s design decision to flatten the version hierarchy baffled me. And has occasionally tripped me up.
评论 #17978527 未加载
sergiotapiaover 6 years ago
The problem in javascript seems more an ideological one where programmers instantly reach for a package that has multiple dependencies of which those dependencies have even more dependencies.<p>There&#x27;s this culture of not caring about bloat it seems in the vast majority of javascript projects. left_pad comes to the mind as the poster boy for this stuff.
评论 #17980105 未加载
jensvdhover 6 years ago
Can we get rid of Yarn instead?
评论 #17981952 未加载