babel-preset-current-node-syntax

raw JSON →
1.2.0 verified Sat Apr 25 auth: no javascript

A Babel preset that automatically enables parsing support for all ECMAScript proposals and syntax features that are currently supported by the active Node.js version. Version 1.2.0 is the latest stable release, updated periodically to align with Node.js release cycles. This preset simplifies configuration by detecting the Node.js version at runtime and applying the appropriate Babel parser plugins, eliminating the need to manually specify plugins for each new syntax feature. It is designed for use with @babel/core v7 or v8 and is specifically tailored for projects targeting the local Node.js environment, such as tools, scripts, or libraries that rely on the latest syntax without transpilation. Key differentiators include zero configuration, automatic updates with Node.js versions, and support for features like import attributes and top-level await.

error Error: Cannot find module 'babel-preset-current-node-syntax'
cause Package not installed or incorrectly required.
fix
Install the preset as a dev dependency: npm install --save-dev babel-preset-current-node-syntax
error Error: Plugin/Preset files are not allowed to export objects, only functions.
cause Using an ESM import to load the CJS preset.
fix
Use require() in babel.config.js or ensure babel is configured to handle CJS modules.
error SyntaxError: Unexpected token 'import'
cause Preset not applied or Babel not configured to use the preset.
fix
Add 'babel-preset-current-node-syntax' to the presets array in babel.config.js and run Babel with --presets flag if using CLI.
gotcha Preset does not support any options; passing configuration options will be silently ignored.
fix Remove any options passed to the preset array.
gotcha Preset is CJS-only; ESM-style default import (import preset from '...') fails in Node <22 with ESM.
fix Use require() or set NODE_OPTIONS='--experimental-require-module' in Node 22+.
gotcha Preset only affects parsing, not transformation; output retains original syntax. Not suitable for targeting older Node versions.
fix Use @babel/preset-env with targets set to older Node versions if transpilation is needed for compatibility.
gotcha Preset is designed for local Node.js version; using it in CI with a different Node version may produce different output.
fix Ensure consistent Node version across environments or use a fixed preset (e.g., @babel/preset-env with specified targets).
npm install babel-preset-current-node-syntax
yarn add babel-preset-current-node-syntax
pnpm add babel-preset-current-node-syntax

Shows minimal setup to transpile modern Node.js syntax without manual plugin configuration using the preset.

// Install: npm install --save-dev babel-preset-current-node-syntax @babel/core
// babel.config.js
module.exports = {
  presets: ['babel-preset-current-node-syntax']
};
// Example input (index.js):
import { fetch } from 'node:module';
const data = await fetch('https://example.com');
// Run: npx babel index.js --out-file output.js
// Output will be identical to input if current Node.js supports the syntax.
console.log('Transpilation complete with automatic syntax detection.');