Registry /
devops / babel-plugin-direct-import
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ module.exports = require('babel-plugin-direct-import')
✗ import babelPluginDirectImport from 'babel-plugin-direct-import'
The plugin is a CommonJS module, so require() is the correct way to import it in Node.js.
plugin usage in .babelrc
✓ {
"plugins": [
["babel-plugin-direct-import", { "modules": ["@mui/material"] }]
]
}
✗ {
"plugins": [
["babel-plugin-direct-import", ["@mui/material"]]
]
}
Since v0.6.0, the plugin expects an object with a `modules` array, not an array directly.
plugin usage in babel.config.js
✓ module.exports = {
plugins: [
["babel-plugin-direct-import", { modules: ["@mui/material"] }]
]
};
✗ module.exports = {
plugins: [
["babel-plugin-direct-import", ["@mui/material"]]
]
};
Same as .babelrc: must use object format since v0.6.0.
Installs the plugin, configures it in .babelrc for MUI v5, and shows transformation of named imports to direct path imports.
npm install --save-dev babel-plugin-direct-import
// .babelrc
{
"plugins": [
["babel-plugin-direct-import", { "modules": ["@mui/material", "@mui/icons-material"] }]
]
}
// Input:
import { Button, TextField } from '@mui/material';
import { Add as AddIcon } from '@mui/icons-material';
// Output:
import Button from '@mui/material/Button/Button.js';
import TextField from '@mui/material/TextField/TextField.js';
import AddIcon from '@mui/icons-material/esm/Add.js';
Errors
Common errors & fixes
Error: [BABEL] unknown: You gave us a visitor for the node type "ImportDeclaration" but it's not a valid type
Using an older version of Babel (v6) with this plugin, which is designed for Babel v7+.
fixUpgrade Babel to v7+ or use a compatible plugin version.
TypeError: Cannot read property 'replace' of undefined
The plugin encountered an import it cannot parse, possibly a namespace import.
fixEnsure you are using only named imports, not `import * as ...`.
Module not found: Can't resolve '@mui/material/Button/Button.js'
The direct path generated by the plugin does not match the actual file structure of the installed MUI version.
fixCheck that the MUI version is supported and that the modules list includes the correct packages. Run `npm ls @mui/material` to verify.
Audit
Dependencies
No dependency data recorded yet.