Course contentsShow
← JavaScript
Lesson 2446 of 2,72350. JavaScript Build ToolingFree lesson

Dependency Resolution

How bundlers trace import/require statements across node_modules to build a complete dependency graph.

Dependency Resolution

You'll learn how bundlers like Webpack and Rollup trace your imports to discover and bundle every module your app needs.

When you write import lodash from 'lodash' or require('express'), you're declaring a dependency—your code needs that module to work. But how does a bundler find lodash in node_modules, then trace lodash's own imports, and repeat recursively until every file is discovered?

How Bundlers Build the Dependency Graph

Dependency resolution is the process of walking through your code's import/require statements and building a complete map—called a dependency graph—of every module your application uses.

  1. Entry Point: The bundler starts at your entry file (e.g., index.js).
  2. Parse Imports: It reads the file and finds all import or require() statements.
  3. Resolve Paths: For each dependency, it determines the actual file path. 'lodash' becomes node_modules/lodash/index.js (following Node's resolution algorithm).
  4. Recurse: The bundler then parses those files, finding their imports, resolving them, and so on.
  5. Graph Complete: When no new dependencies are found, you have a complete graph of every module your app depends on.

Why It Matters

Without dependency resolution, bundlers couldn't know which files to include. The graph also enables:

  • Tree shaking: removing unused exports
  • Code splitting: creating separate bundles
  • Optimizing load order: ensuring dependencies load before dependents

Key Takeaway:
Dependency resolution is how bundlers trace every import and require() from your entry file through node_modules, recursively building a complete graph of all modules your application needs to run.