babel-helper-simplify-module

raw JSON →
2.2.1 verified Sat Apr 25 auth: no javascript maintenance

This package provides Babel utilities to transform and simplify module structures by exploding imports and exports into a normalized form. Current stable version is 2.2.1, with low release cadence. It is intended for internal use in Babel tooling, not for direct consumption in most projects. It differs from alternatives like babel-plugin-transform-modules-commonjs by focusing on structure normalization rather than module system conversion. Typically used in conjunction with babel-explode-module.

error TypeError: Cannot read properties of undefined (reading 'node')
cause Passing a path that is not a Program node to simplifyModule
fix
Ensure you call simplifyModule on a Program path, e.g., traverse with Program enter.
error Module not found: Can't resolve 'babel-helper-simplify-module'
cause Package not installed
fix
Run 'npm install babel-helper-simplify-module'
gotcha simplifyModule mutates the program path in place; always call it within a Babel traversal
fix Ensure you pass a valid Babel NodePath to simplifyModule.
deprecated This package is no longer actively maintained; consider using @babel/helper-module-transforms for similar functionality
fix Switch to @babel/helper-module-transforms if possible.
npm install babel-helper-simplify-module
yarn add babel-helper-simplify-module
pnpm add babel-helper-simplify-module

Demonstrates importing simplifyModule and using it on a Babel AST program path to normalize module structure.

import { simplifyModule } from 'babel-helper-simplify-module';
import { parse, traverse } from '@babel/core';

const code = `
import foo from 'mod';
import { bar } from 'mod';
export default function() {}
export const baz = 42;
export * from 'bam';
`;

const ast = parse(code, { sourceType: 'module' });
traverse(ast, {
  Program(path) {
    simplifyModule(path);
    path.stop();
  }
});

// simplified AST is now in ast
console.log(JSON.stringify(ast, null, 2));