Traceur Compiler
raw JSON → 0.0.111 verified Fri May 01 auth: no javascript maintenance
Traceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to use ES6 and experimental ES.next features by transpiling them to ES5. Version 0.0.111 is the latest stable release. It was developed by Google to inform the design of new JavaScript features and supports a wide range of proposals including async functions, generators, spread properties, and JSX. It provides both CommonJS and browser builds. Traceur is now largely superseded by Babel, but remains useful for legacy projects or understanding early transpiler design.
Common errors
error Cannot find module 'traceur/dist/commonjs/Compiler' ↓
cause The Compiler module was restructured in 0.0.108 and is no longer at the old path.
fix
Use: const { Compiler } = require('traceur/dist/commonjs/Compiler');
error TypeError: traceur.compile is not a function ↓
cause The compile function is deprecated and not exported as a standalone function in some versions.
fix
Use the Compiler class or ensure you are using a version that exports compile (e.g., <0.0.108).
error ReferenceError: require is not defined ↓
cause Trying to use Traceur in a browser environment without a bundler.
fix
Use the browser build: <script src='node_modules/traceur/bin/traceur.js'></script>
error Error: Cannot find module 'glob' ↓
cause Missing optional dependency 'glob' which is required for some internal operations.
fix
Install 'glob' as a dependency: npm install glob
Warnings
breaking The Compiler class is no longer exported from the main 'traceur' module. Import it from 'traceur/dist/commonjs/Compiler' instead. ↓
fix Change import from require('traceur').Compiler to require('traceur/dist/commonjs/Compiler').Compiler
deprecated The `compile` function exported from the main module is deprecated in favor of using the Compiler class. ↓
fix Use Compiler instance: new Compiler().compile()
gotcha When using the command-line tool, you must install Traceur globally or use npx. The bin/traceur file may have a shebang issue on Windows. ↓
fix Use `npx traceur` or install globally: `npm install -g traceur`
breaking In version 0.0.108, runtime modules were moved into individual modules under 'traceur/dist/commonjs/runtime/modules/'. Requiring the full runtime is no longer sufficient. ↓
fix Import specific runtime modules as needed, e.g., require('traceur/dist/commonjs/runtime/modules/call.js')
deprecated The `--experimental` flag has been deprecated and may not work as expected in recent versions. ↓
fix Use specific feature flags like `--async-functions` instead.
gotcha Node.js must be >=0.10 (engines field). Using Traceur with very old Node <0.10 will fail. ↓
fix Update Node.js to >=0.10 or use an older version of Traceur.
Install
npm install traceur yarn add traceur pnpm add traceur Imports
- traceur wrong
import traceur from 'traceur';correctconst traceur = require('traceur'); - compile wrong
const compile = require('traceur').compile;correctconst { compile } = require('traceur'); - TraceurCompiler wrong
const Compiler = require('traceur').Compiler;correctconst { Compiler } = require('traceur/dist/commonjs/Compiler');
Quickstart
const traceur = require('traceur');
const fs = require('fs');
const code = fs.readFileSync('example.es6', 'utf8');
try {
const result = traceur.compile(code, {
sourceMaps: false,
modules: 'commonjs'
});
if (result.errors && result.errors.length) {
console.error('Errors:', result.errors);
} else {
console.log(result.js);
if (result.sourceMap) {
console.log('Source map generated');
}
}
} catch (e) {
console.error('Compilation failed:', e);
}