Module resolution in Node and browser bundlers
Learn how imports are resolved: relative vs bare specifiers, file extensions (.js/.mjs/.cjs), index files, and simple package entry points.
Big picture
Goal: Know how import paths resolve.
- Relative vs bare specifiers
- Use explicit .js (safe default)
- index.js in folders
- Package entry points (main/exports, taste)

Relative vs bare
Relative imports start with ./ or ../. Bare imports point to installed packages.
// Relative path imports start with ./ or ../
// Bare specifiers refer to packages installed (e.g., "lodash")
const examples = [
"import { sum } from \\"./math.js\\"; // relative, file nearby",
"import leftPad from \\"left-pad\\"; // bare, from node_modules",
"import thing from \\"../lib/thing.js\\"; // parent folder"
];
console.log("specifiers:");
for (const line of examples) console.log(line);
All lessons in this course
- ESM basics — import/export, default vs named
- CommonJS basics — require/module.exports and exports
- Module resolution in Node and browser bundlers