ES6 Module Transpiler (rhengles fork)

raw JSON →
0.3.0 verified Fri May 01 auth: no javascript deprecated

Experimental compiler that transforms a subset of ES6 module syntax into AMD or CommonJS modules. Version 0.3.0, unmaintained since 2015. Key differentiator: early ES6 module syntax experimentation, but the syntax it supports differs from the finalized ES6 spec. No longer recommended for new projects; use Babel or TypeScript instead.

error Cannot find module 'es6-module-transpiler'
cause The package is not installed or the import path is incorrect.
fix
Run npm install es6-module-transpiler and ensure the module is in node_modules.
error Compiler is not a constructor
cause Using `require('es6-module-transpiler')` returns an object with `Compiler` property, but if you import the default incorrectly.
fix
Use const { Compiler } = require('es6-module-transpiler');
error Unexpected token 'export'
cause The JavaScript file uses ES6 module syntax but is not processed by the transpiler.
fix
Run the code through compile-modules or use the Compiler class programmatically.
deprecated The ES6 module syntax supported by this transpiler is outdated and not compliant with the finalized ES6 specification.
fix Migrate to Babel or TypeScript for modern module transpilation.
gotcha The `compile-modules` CLI command may not be installed correctly if the package is not installed globally with the exact URL from Git.
fix Use `npx es6-module-transpiler` or install globally via `npm install -g es6-module-transpiler` if available, but prefer library usage.
gotcha The transpiler does not support destructuring or other modern JavaScript features—only a strict subset of ES6 module syntax.
fix Write code using only supported syntax: export/import declarations, no destructuring, no default exports for modules.
npm install es6-module-transpiler-rhengles
yarn add es6-module-transpiler-rhengles
pnpm add es6-module-transpiler-rhengles

Shows how to use the Compiler class to transpile ES6 module syntax to AMD and CommonJS.

const { Compiler } = require('es6-module-transpiler');

const code = `
  export function square(x) {
    return x * x;
  }
`;

const compiler = new Compiler(code, 'myModule');
const amdOutput = compiler.toAMD();
console.log(amdOutput);
// Outputs AMD define(...)

const cjsOutput = compiler.toCJS();
console.log(cjsOutput);
// Outputs CommonJS exports...