{"id":19012,"library":"babel-plugin-add-import-extension","title":"babel-plugin-add-import-extension","description":"A Babel plugin that automatically adds file extensions to import and export specifiers for local modules, useful when using TypeScript with Babel and not writing explicit extensions in source files. Version 1.6.0 is the latest stable release, updated occasionally. It defaults to adding .js extension, with options to specify custom extension, replace existing extensions, and configure observed script extensions. Differentiates itself by focusing solely on extension addition without other transforms.","status":"active","version":"1.6.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","babel","plugin","import","export","transform","extension"],"install":[{"cmd":"npm install babel-plugin-add-import-extension","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-add-import-extension","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-add-import-extension","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for plugin to work","package":"@babel/core","optional":false}],"imports":[{"note":"Use string shorthand when no options are needed, array form only when specifying options.","wrong":"plugins: [['babel-plugin-add-import-extension', {}]] (unnecessary nesting without options)","symbol":"default","correct":"plugins: ['babel-plugin-add-import-extension']"},{"note":"Options must be supplied via the array form; the string shorthand does not accept options.","wrong":"plugins: ['babel-plugin-add-import-extension', { extension: 'mjs' }] (second argument is misinterpreted)","symbol":"options","correct":"plugins: [['babel-plugin-add-import-extension', { extension: 'mjs' }]]"},{"note":"This plugin is configured as a string in Babel config, not imported programmatically.","wrong":"import babelPluginAddImportExtension from 'babel-plugin-add-import-extension' (not importable as a module)","symbol":"configuration","correct":"module.exports = { plugins: ['babel-plugin-add-import-extension'] }"}],"quickstart":{"code":"// Install\nnpm install --save-dev babel-plugin-add-import-extension\n\n// babel.config.js\nmodule.exports = {\n  plugins: [\n    ['babel-plugin-add-import-extension', { extension: 'js' }]\n  ]\n};\n\n// Input: import { add } from './math';\n// Output: import { add } from './math.js';","lang":"javascript","description":"Installs the plugin, configures it to add .js extension, and shows a simple import transformation."},"warnings":[{"fix":"Ensure imports from node_modules are left untouched as intended; no action needed.","message":"Plugin only adds extensions to local modules (not in node_modules). It does not affect bare specifiers for npm packages.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need to replace other extensions (e.g., .mjs), add them to observedScriptExtensions.","message":"When using replace: true, only extensions listed in observedScriptExtensions are replaced. Defaults are js, ts, jsx, tsx.","severity":"gotcha","affected_versions":"all"},{"fix":"Use additional Babel plugins for dynamic imports if needed.","message":"The plugin does not handle dynamic imports (import()) or require() calls; only static import/export declarations.","severity":"gotcha","affected_versions":"all"},{"fix":"Refer to current GitHub repo for issues and documentation.","message":"The repository was migrated back to GitHub after being on SourceHut; old issues lost.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev babel-plugin-add-import-extension","cause":"Plugin not installed or not in devDependencies.","error":"Error: Cannot find module 'babel-plugin-add-import-extension'"},{"fix":"Ensure plugin is specified as [\"babel-plugin-add-import-extension\", { extension: 'js' }] not as separate arguments.","cause":"Incorrect plugin configuration order or missing options array.","error":"TypeError: Cannot read properties of undefined (reading 'configure')"},{"fix":"Upgrade @babel/core to >=7.0.0.","cause":"Using an incompatible version of @babel/core (less than 7.0.0).","error":"The plugin \"babel-plugin-add-import-extension\" didn't return a visitor object."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}