{"id":19105,"library":"babel-plugin-module-extension","title":"babel-plugin-module-extension","description":"A Babel plugin that transforms module import/require extensions during compilation. Version 0.1.3 (latest, but no recent updates). It allows mapping original extensions (e.g., .less) to new ones (e.g., .css) or removing extensions entirely. Unlike babel-plugin-transform-import-extension, it focuses solely on extension replacement. Low maintenance, likely experimental.","status":"active","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/beilunyang/babel-plugin-module-extension","tags":["javascript","babel-plugin","transform extension"],"install":[{"cmd":"npm install babel-plugin-module-extension","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-module-extension","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-module-extension","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Used as a Babel plugin name in config, not imported directly.","wrong":"import plugin from 'babel-plugin-module-extension';\n// Works only in modern JavaScript, not as Babel plugin API","symbol":"babel-plugin-module-extension","correct":"// Use in .babelrc as plugin reference\n{\n  \"plugins\": [\n    [\"module-extension\", { \"less\": \"css\", \"js\": \"\" }]\n  ]\n}"},{"note":"CommonJS require for Node.js or e2e test setups.","wrong":"","symbol":"require('babel-plugin-module-extension')","correct":"const plugin = require('babel-plugin-module-extension');"},{"note":"ESM import returns the plugin function directly. No .default needed.","wrong":"const plugin = require('babel-plugin-module-extension').default;\n// No default export, returns function directly","symbol":"plugin function","correct":"import plugin from 'babel-plugin-module-extension';"}],"quickstart":{"code":"// Run via Babel CLI or programmatic API.\n// Example .babelrc\n{\n  \"plugins\": [\n    [\"module-extension\", {\n      \".less\": \".css\",\n      \".ts\": \".js\"\n    }]\n  ]\n}\n// Input: import styles from './style.less';\n// Output: import styles from './style.css';","lang":"javascript","description":"Configures module-extension plugin to replace .less with .css and .ts with .js in import statements."},"warnings":[{"fix":"Test compatibility. Consider using babel-plugin-transform-import-extension instead.","message":"Plugin may not work with Babel 7+ because the API has changed (deprecated babel.transform).","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Ensure parser supports import() (e.g., @babel/plugin-syntax-dynamic-import).","message":"Only transforms import/require statements, not dynamic import() calls in some Babel presets.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use keys with dot prefix: {'.less': '.css'}.","message":"Options keys must include the leading dot (e.g., '.less' vs 'less') for correct matching in some versions.","severity":"gotcha","affected_versions":"<0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use explicit imports for side-effect modules.","cause":"Babel plugin runs on import statements only, not dynamic requires or side-effect imports.","error":"Error: Module side-effects are not supported."},{"fix":"Provide at least an empty object: [\"module-extension\", {}].","cause":"Missing options object in plugin config.","error":"TypeError: Cannot read property 'includes' of undefined"},{"fix":"Use an empty string with dot prefix for removal: {\".js\": \"\"}.","cause":"Empty string as target for an extension mapping without dot prefix.","error":"babel-plugin-module-extension: Unrecognized extension ''"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}