babel-preset-node8
raw JSON → 1.2.0 verified Sat Apr 25 auth: no javascript maintenance
Babel 6 preset for Node.js 7.10–8.x. This preset enables ES2015+ features that are not natively supported in Node 7.10+, including class properties, object rest/spread, export extensions, async generators, and trailing function commas. It also includes production-specific minification and dead code elimination plugins. Version 1.2.0 is the latest stable release. This package is specifically tailored for Node 7.10 to 8.x and is not intended for use with other Node versions or Babel 7.
Common errors
error Error: Plugin/Preset files are not allowed to export objects, only functions. In /path/to/node_modules/babel-preset-node8/index.js ↓
cause Using this preset with Babel 7 or newer, which expects presets to export functions instead of objects.
fix
Migrate to Babel 7 and use @babel/preset-env instead.
error ReferenceError: regeneratorRuntime is not defined ↓
cause The preset does not include async-to-generator or regenerator runtime; async/await must be natively supported by Node 7.10+.
fix
Ensure Node version is >=7.10, or add @babel/plugin-transform-runtime and @babel/runtime.
error Module not found: Can't resolve 'babel-preset-node8' in /path/to/project ↓
cause The preset is not installed or the package name is misspelled.
fix
Run 'npm install --save-dev babel-preset-node8' and ensure package.json includes it.
Warnings
deprecated Babel 6 is deprecated; Babel 7 is now standard. This preset does not support Babel 7. ↓
fix Use @babel/preset-env with targets for Node 8 instead.
breaking This preset is specifically for Node 7.10–8.x. Using it with Node 6 or Node 9+ may cause compatibility issues. ↓
fix Use babel-preset-node6 for Node 6, or babel-preset-env for broader Node support.
gotcha The production plugins (block-scoping, for-of, minify) are automatically applied based on NODE_ENV. If NODE_ENV is not set, production plugins are not used. ↓
fix Set NODE_ENV=production explicitly to enable production optimizations.
gotcha syntax-trailing-function-commas is a syntax plugin only; it does not transform code. Ensure that your target Node version supports trailing commas in function calls (Node 8). ↓
fix If targeting Node <8, do not rely on this plugin for runtime support.
Install
npm install babel-preset-node8 yarn add babel-preset-node8 pnpm add babel-preset-node8 Imports
- default (preset) wrong
const babelPresetNode8 = require('babel-preset-node8')correctimport babelPresetNode8 from 'babel-preset-node8' - createPreset wrong
import { createPreset } from 'babel-preset-node8'correctimport createPreset from 'babel-preset-node8/lib/create-preset' - env wrong
import { env } from 'babel-preset-node8'correctimport envPreset from 'babel-preset-node8/lib/env'
Quickstart
npm install --save-dev babel-preset-node8
# .babelrc
{
"presets": ["node8"]
}
# Use with babel-cli
# babel src --out-dir dist --presets node8