<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Phantom-Packages on MyVar.dev</title><link>https://gibbok.github.io/myvar/tags/phantom-packages/</link><description>Recent content in Phantom-Packages on MyVar.dev</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 31 Mar 2026 19:26:04 +0000</lastBuildDate><atom:link href="https://gibbok.github.io/myvar/tags/phantom-packages/index.xml" rel="self" type="application/rss+xml"/><item><title>NodeJS NPM Phantom Dependencies Understanding and Mitigation</title><link>https://gibbok.github.io/myvar/nodejs/nodejs-npm-phantom-dependencies-understanding-and-mitigation/</link><pubDate>Tue, 31 Mar 2026 19:26:04 +0000</pubDate><guid>https://gibbok.github.io/myvar/nodejs/nodejs-npm-phantom-dependencies-understanding-and-mitigation/</guid><description>&lt;h2 id="overview"&gt;Overview&lt;/h2&gt;
&lt;p&gt;NodeJS and NPM manage package dependencies by physically representing the dependency graph on disk within &lt;code&gt;node_modules&lt;/code&gt; folders. This system, combined with NodeJS&amp;rsquo;s module resolution algorithm, introduces &lt;strong&gt;phantom dependencies&lt;/strong&gt;: undeclared packages a project implicitly relies upon due to the flattened &lt;code&gt;node_modules&lt;/code&gt; structure or ancestral &lt;code&gt;node_modules&lt;/code&gt; directories.&lt;/p&gt;
&lt;h2 id="key-insights"&gt;Key Insights&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;NPM models package dependencies using physical folder copies on disk, diverging from traditional package managers that use central package stores.&lt;/li&gt;
&lt;li&gt;NodeJS&amp;rsquo;s module resolution rules augment the file system&amp;rsquo;s tree structure, introducing &amp;ldquo;extra graph edges&amp;rdquo; that allow modules to be found outside of direct declarations.&lt;/li&gt;
&lt;li&gt;The installed &lt;code&gt;node_modules&lt;/code&gt; tree is not unique and depends on NPM&amp;rsquo;s installation heuristics, which are sensitive to factors like package addition order.&lt;/li&gt;
&lt;li&gt;Phantom dependencies lead to difficult-to-diagnose issues such as &lt;strong&gt;incompatible versions&lt;/strong&gt; and &lt;strong&gt;missing dependencies&lt;/strong&gt; for consumers of a published library.&lt;/li&gt;
&lt;li&gt;In monorepos, root-level &lt;code&gt;node_modules&lt;/code&gt; folders can introduce even more insidious phantom dependencies for nested projects.&lt;/li&gt;
&lt;li&gt;Tools like Rush and PNPM mitigate these problems by enforcing strict dependency declarations, preventing accidental reliance on phantom packages.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="technical-details"&gt;Technical Details&lt;/h2&gt;
&lt;h3 id="traditional-vs-nodejs-dependency-resolution"&gt;Traditional vs. NodeJS Dependency Resolution&lt;/h3&gt;
&lt;p&gt;Conventional package managers represent package dependencies as a directed acyclic graph (DAG), where a central store often houses packages, and module resolvers traverse this graph. DAGs can feature &amp;ldquo;diamond dependencies,&amp;rdquo; where multiple packages depend on a common sub-dependency.&lt;/p&gt;</description></item></channel></rss>