babel-preset-current-node-syntax
raw JSON →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.
Common errors
error Error: Cannot find module 'babel-preset-current-node-syntax' ↓
error Error: Plugin/Preset files are not allowed to export objects, only functions. ↓
error SyntaxError: Unexpected token 'import' ↓
Warnings
gotcha Preset does not support any options; passing configuration options will be silently ignored. ↓
gotcha Preset is CJS-only; ESM-style default import (import preset from '...') fails in Node <22 with ESM. ↓
gotcha Preset only affects parsing, not transformation; output retains original syntax. Not suitable for targeting older Node versions. ↓
gotcha Preset is designed for local Node.js version; using it in CI with a different Node version may produce different output. ↓
Install
npm install babel-preset-current-node-syntax yarn add babel-preset-current-node-syntax pnpm add babel-preset-current-node-syntax Imports
- default export wrong
import preset from 'babel-preset-current-node-syntax'correctmodule.exports = require('babel-preset-current-node-syntax') - preset in babel.config.js wrong
module.exports = { presets: ['@babel/preset-current-node-syntax'] }correctmodule.exports = { presets: ['babel-preset-current-node-syntax'] } - with options (no options supported) wrong
module.exports = { presets: [['babel-preset-current-node-syntax', { modules: false }]] }correctmodule.exports = { presets: [['babel-preset-current-node-syntax', {}]] }
Quickstart
// 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.');