Babel plugin that adds Jest-like moduleNameMapper support to Babel, enabling import path rewriting with special tokens <pkgDir> and <rootDir>. <pkgDir> resolves to the directory of the closest package.json, making it ideal for monorepos. Current stable version is 1.2.0. Release cadence is low; maintained. Key differentiator: supports <pkgDir> for monorepo-friendly path resolution, which is lacking in Jest and Webpack. Alternative to babel-plugin-module-resolver with different token semantics.
npm install babel-plugin-module-name-mapperVerified import paths — ran on the pinned version, not inferred.
Shows installation, configuration with multiple mappings using <pkgDir> and <rootDir> tokens, and usage example replacing relative path hell.
Always use ^ and $ boundaries in your moduleNameMapper patterns.
Add to plugins array only.
Use <pkgDir> for monorepo package root; <rootDir> remains available.
Evaluate migration to babel-plugin-module-resolver if newer features are needed.
Ensure pattern uses ^src/(.*) and replacement uses correct token like <pkgDir>/src/$1.
Use plugins: [['module-name-mapper', { moduleNameMapper: {} }]] even if no mappings.Pass an object with moduleNameMapper key: plugins: [['module-name-mapper', { moduleNameMapper: { ... } }]].No dependency data recorded yet.