Webpack/V5/Json Imports To Default Imports
Made for
Webpack
Last update
Apr 17, 2025
This codemod migrates imports from JSON modules that use named exports to use default exports instead.
This codemod transforms named imports from JSON files into default imports, adhering to the new ECMAScript specification and Webpack v5 compatibility. Named imports from JSON modules are no longer supported.
Example
Before
import { version } from "./package.json";console.log(version);
After
import pkg from "./package.json";console.log(pkg.version);
,
Before
import { version, name, description } from "./package.json";console.log(version, name, description);
After
import pkg from "./package.json";console.log(pkg.version, pkg.name, pkg.description);
,
Before
import { data } from './config.json';console.log(data.nested.key, data.anotherKey);
After
import config from './config.json';console.log(config.data.nested.key, config.data.anotherKey);
,
Before
import { key1, key2 } from './config.json';console.log(key1, key2);
After
import config from './config.json';console.log(config.key1, config.key2);
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community