Registry / serialization / es6-module-crosspiler

es6-module-crosspiler

JSON →
library2.0.1jsnpmunverified

An ES6 and CommonJS cross-compatible transpiler that enables mixed usage of ES6 modules and CommonJS modules during migration. Version 2.0.1 is the latest stable release but appears to be in maintenance mode as the project has seen no recent updates and uses legacy dependencies like recast and esprima-fb. Unlike higher-level transpilers (e.g., Babel), this is a lower-level library that operates on recast ASTs, allowing flexibility in custom build pipelines but lacking file system resolution and custom formatters.

npm install es6-module-crosspiler
INSTALL
IMPORT
SIG · ES6-MODULE-CROSSPI
E
es6-module-crosspiler
serializationjavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Module
import Module from 'es6-module-crosspiler'
const Module = require('es6-module-crosspiler').default
The library uses a default export. In CommonJS, require returns the default export directly.
Module.transform
Module.transform(ast, options)
Module.transform(ast, { ... }) // incorrect: options should be passed as second argument
Static convenience method; must be called on the Module class, not an instance.
Module.dependenciesOf
Module.dependenciesOf(ast)
m.dependenciesOf(ast) // instance method does not exist; use static method
Static convenience method; returns an array of dependency names.

This shows how to transpile a simple ES6 import statement to CommonJS using recast, esprima-fb, and the crosspiler.

var recast = require('recast'); var esprima = require('esprima-fb'); var Module = require('es6-module-crosspiler'); var code = 'import { foo } from \'./lib\';'; var ast = recast.parse(code, { esprima: esprima }); var m = new Module(ast, { dependencies: { './lib': { type: 'module', default: false } } }); var transformedAst = m.transform(); var result = recast.print(transformedAst); console.log(result.code);
Debug
Known issues
breakingThe library depends on 'esprima-fb', which is deprecated and may not support recent ES6 features.
fix
Use a more modern transpiler like Babel or TypeScript for ES6 module transpilation.
affects: >=1.0.0
gotchaThe default export handling differs from standard ES6 module semantics: CommonJS modules imported from ES6 modules are treated as default exports without the .default property.
fix
When cross-compiling, ensure that CommonJS modules do not export a .default property, as it will be overridden.
affects: >=1.0.0
deprecatedThe package has not been updated since 2015 and uses deprecated dependencies like 'recast' and 'esprima-fb'.
fix
Migrate to a maintained transpiler such as Babel or esbuild.
affects: >=1.0.0
gotchaThe library requires explicit metadata for each dependency (.set() or constructor), otherwise it defaults to { type: 'module', default: false }.
fix
Always provide dependency metadata to avoid incorrect transpilation.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'import'
The JavaScript parser does not support ES6 module syntax (requires esprima-fb or similar).
fix
Use a custom esprima that supports ES6 modules, e.g., 'esprima-fb', when calling recast.parse().
The module was imported incorrectly, e.g., using named import instead of default import.
Attempting 'import { Module } from ...' instead of 'import Module from ...'
fix
Use default import: import Module from 'es6-module-crosspiler'
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
recastrequiredUsed for AST parsing and printing; the library expects a recast AST as input.
esprima-fboptionalRequired for parsing ES6 module syntax, as official esprima versions did not fully support ES6 modules at the time of writing.
Agent activity
2 hits · last 30 days
node
2
Resources
es6-module-crosspiler — npm install es6-module-crosspiler · libregistry