babel-plugin-replace-ts-export-assignment

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

A Babel plugin that enables TypeScript's `export =` assignment syntax to be used when compiling with `@babel/preset-typescript`. It transforms `export =` into `module.exports =` to maintain CommonJS semantics. Current version 0.0.2 is a minimal, single-purpose plugin with no active development since late 2022. Key differentiators: lightweight and focused, no configuration needed, works seamlessly with `@babel/preset-typescript`. Release cadence is low; only two minor versions exist.

error Error: [BABEL] ...: Cannot find module 'babel-plugin-replace-ts-export-assignment'
cause Plugin not installed or not in node_modules.
fix
Run npm install --save-dev babel-plugin-replace-ts-export-assignment.
error SyntaxError: 'import' and 'export' may only appear at the top level
cause Plugin not active or Babel preset missing; TypeScript export assignment not compiled.
fix
Ensure the plugin is listed in Babel config and @babel/preset-typescript is installed.
gotcha Plugin only works with `@babel/preset-typescript`; other TypeScript presets may not support `export =`.
fix Ensure `@babel/preset-typescript` is in your Babel presets.
gotcha Transformation is a simple text replacement; it does not check for JavaScript syntax errors after replacement.
fix Ensure the `export =` statement is syntactically correct with a valid expression.
gotcha This plugin modifies `module.exports` directly, which may conflict with other plugins or corejs polyfills.
fix Use only one plugin that modifies module.exports to avoid overwrites.
npm install babel-plugin-replace-ts-export-assignment
yarn add babel-plugin-replace-ts-export-assignment
pnpm add babel-plugin-replace-ts-export-assignment

Demonstrates adding the plugin to Babel config and transforming `export =` into `module.exports`.

// babel.config.js
module.exports = {
  presets: [
    "@babel/preset-env",
    "@babel/preset-typescript"
  ],
  plugins: [
    "babel-plugin-replace-ts-export-assignment"
  ]
};

// source.ts
export = { foo: "bar" };

// After Babel transform:
// "use strict";
// module.exports = { foo: "bar" };