{"id":26776,"library":"babel-plugin-module-resolve","title":"babel-plugin-module-resolve","description":"A Babel plugin that allows module imports using Webpack-like aliases and custom root directories, resolving paths similar to webpack's enhanced-resolve. Version 1.7.0 (current stable) last released in 2022 with low release cadence. It supports both custom alias configuration and automatic usage of jsconfig/tsconfig paths, making it a lightweight alternative to babel-plugin-module-resolver. Includes TypeScript types and supports ESM and CJS import patterns.","status":"maintenance","version":"1.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/planjs/stan","tags":["javascript","typescript"],"install":[{"cmd":"npm install babel-plugin-module-resolve","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-module-resolve","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-module-resolve","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for Babel plugin functionality","package":"@babel/core","optional":false}],"imports":[{"note":"For use in .babelrc or Babel config files; import is not used directly in code. Plugin is CommonJS by default.","wrong":"import plugin from 'babel-plugin-module-resolve'","symbol":"default","correct":"module.exports = require('babel-plugin-module-resolve')"},{"note":"Plugin name in config is 'module-resolve', not the full package name.","wrong":"plugins: ['babel-plugin-module-resolve']","symbol":"plugin","correct":"plugins: [['module-resolve', { roots: ['./src'] }]]"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-module-resolve\n// In .babelrc or babel.config.js:\n{\n  \"plugins\": [\n    [\"module-resolve\", {\n      \"roots\": [\"./src\"],\n      \"alias\": {\n        \"@utils\": \"./src/utils\",\n        \"components\": \"./src/components\"\n      }\n    }]\n  ]\n}\n// Now import using alias:\nimport { helper } from '@utils/helper'; // resolves to ./src/utils/helper","lang":"javascript","description":"Basic setup with alias configuration to simplify import paths."},"warnings":[{"fix":"Test paths thoroughly; if issues arise, use absolute paths in alias.","message":"Plugin uses enhanced-resolve internally; resolving behavior may differ from Babel's default path resolution for symlinks or non-standard file structures.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"If upgrading from <1.0, explicitly configure alias or use tsconfig paths.","message":"Version 1.0 changed default alias from mapping '@' to 'src' to no default alias unless specified in config or tsconfig.","severity":"breaking","affected_versions":">=1.0"},{"fix":"Use absolute paths in alias or set roots to an absolute path.","message":"Plugin resolves based on the file's location, not the project root. Relative aliases may behave unexpectedly.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add alias in plugin options: { alias: { '@utils': './src/utils' } }","cause":"Alias not configured or roots not set correctly.","error":"Error: Cannot find module '@utils'"},{"fix":"Check that the alias mapping is correct and the directory exists. Use absolute paths if needed.","cause":"Alias is not resolving the path correctly.","error":"Module not found: Can't resolve 'components/Button' in '/path/to/file'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}