Registry / type-stubs / babel-plugin-add-import-extension

babel-plugin-add-import-extension

JSON →
library1.6.0jsnpmunverified

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.

npm install babel-plugin-add-import-extension
INSTALL
IMPORT
SIG · BABEL-PLUGIN-ADD-I
B
babel-plugin-add-import-extension
type-stubsjavascriptv1.6.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
plugins: ['babel-plugin-add-import-extension']
plugins: [['babel-plugin-add-import-extension', {}]] (unnecessary nesting without options)
Use string shorthand when no options are needed, array form only when specifying options.
options
plugins: [['babel-plugin-add-import-extension', { extension: 'mjs' }]]
plugins: ['babel-plugin-add-import-extension', { extension: 'mjs' }] (second argument is misinterpreted)
Options must be supplied via the array form; the string shorthand does not accept options.
configuration
module.exports = { plugins: ['babel-plugin-add-import-extension'] }
import babelPluginAddImportExtension from 'babel-plugin-add-import-extension' (not importable as a module)
This plugin is configured as a string in Babel config, not imported programmatically.

Installs the plugin, configures it to add .js extension, and shows a simple import transformation.

// Install npm install --save-dev babel-plugin-add-import-extension // babel.config.js module.exports = { plugins: [ ['babel-plugin-add-import-extension', { extension: 'js' }] ] }; // Input: import { add } from './math'; // Output: import { add } from './math.js';
Debug
Known issues
gotchaPlugin only adds extensions to local modules (not in node_modules). It does not affect bare specifiers for npm packages.
fix
Ensure imports from node_modules are left untouched as intended; no action needed.
affects: all
gotchaWhen using replace: true, only extensions listed in observedScriptExtensions are replaced. Defaults are js, ts, jsx, tsx.
fix
If you need to replace other extensions (e.g., .mjs), add them to observedScriptExtensions.
affects: all
gotchaThe plugin does not handle dynamic imports (import()) or require() calls; only static import/export declarations.
fix
Use additional Babel plugins for dynamic imports if needed.
affects: all
deprecatedThe repository was migrated back to GitHub after being on SourceHut; old issues lost.
fix
Refer to current GitHub repo for issues and documentation.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-add-import-extension'
Plugin not installed or not in devDependencies.
fix
Run npm install --save-dev babel-plugin-add-import-extension
TypeError: Cannot read properties of undefined (reading 'configure')
Incorrect plugin configuration order or missing options array.
fix
Ensure plugin is specified as ["babel-plugin-add-import-extension", { extension: 'js' }] not as separate arguments.
The plugin "babel-plugin-add-import-extension" didn't return a visitor object.
Using an incompatible version of @babel/core (less than 7.0.0).
fix
Upgrade @babel/core to >=7.0.0.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency required for plugin to work
Agent activity
40 hits · last 30 days
node
35
OpenAI (training)
1
Resources
babel-plugin-add-import-extension — npm install babel-plugin-add-import-extension · libregistry