nuclide-node-transpiler
raw JSON → 0.7.1 verified Fri May 01 auth: no javascript
A small Node.js module used internally by the Nuclide project to transpile JavaScript files from ES6+ to ES5 or ES6. v0.7.1 is the latest stable version. Release cadence is low; it is not actively updated outside of Nuclide. Key differentiator: it is designed specifically for Node.js server-side code, not for browser bundling, and integrates with Nuclide's module system.
Common errors
error Error: Cannot find module 'babel-preset-fbjs' ↓
cause Missing required Babel preset that is a dependency of nuclide-node-transpiler.
fix
Run npm install --save-dev babel-preset-fbjs or include it in your project's dependencies.
error TypeError: transpile is not a function ↓
cause Using CommonJS require on an ESM-only export.
fix
Use the ESM import statement: import transpile from 'nuclide-node-transpiler'.
error Error: Plugin/Preset files are not allowed to export objects ↓
cause Babel 7 plugin/preset format is incompatible with Babel 6 used by the package.
fix
Downgrade to Babel 6 plugins/presets or use a different transpilation tool.
Warnings
breaking The package uses Babel 6 presets by default; Babel 7 presets are not supported. ↓
fix Use @babel/core and @babel/preset-env with the package, but note that the package may not be compatible due to plugin/preset API changes.
deprecated The package is deprecated in favor of using Babel directly. ↓
fix Replace with direct Babel usage: npm install @babel/core @babel/preset-env and use babel.transform or babel.transformFile.
gotcha The package attempts to automatically transpile files during Node.js startup via require hook; this may interfere with other Babel configurations. ↓
fix Disable the automatic hook by setting the environment variable NUCLIDE_NODE_TRANSPILER_DISABLE=1.
gotcha The default export is a function that mutates the input options object; unexpected side effects may occur. ↓
fix Clone the options object before passing if you need to reuse it: const result = transpile(code, Object.assign({}, options));
Install
npm install nuclide-node-transpiler yarn add nuclide-node-transpiler pnpm add nuclide-node-transpiler Imports
- default wrong
const transpile = require('nuclide-node-transpiler')correctimport transpile from 'nuclide-node-transpiler' - transpileFile wrong
const transpileFile = require('nuclide-node-transpiler').transpileFilecorrectimport { transpileFile } from 'nuclide-node-transpiler' - options
import { options } from 'nuclide-node-transpiler'
Quickstart
import transpile, { transpileFile, options } from 'nuclide-node-transpiler';
// Transpile a string of code
const code = 'const x = (a) => a + 1;';
const result = transpile(code, { presets: ['@babel/preset-env'] });
console.log(result.code);
// Transpile a file
const fileResult = transpileFile('./file.js', { presets: ['@babel/preset-env'] });
console.log(fileResult.code);
// Use custom options
options.presets = ['@babel/preset-env'];
const customResult = transpile(code, options);
console.log(customResult.code);