rollup-plugin-ecma-version-validator
raw JSON → 0.2.13 verified Mon Apr 27 auth: no javascript
A Rollup plugin that verifies the ECMAScript version of bundle files by checking syntax against a specified target (default ES5). It uses Acorn under the hood to parse the output and reports any syntax features that exceed the target version. This is useful for ensuring production bundles don't include unsupported syntax for older environments. The current stable version is 0.2.13, with infrequent releases. It supports Rollup ^2.16.1 and ^3.x. Unlike other ECMAScript compliance tools, this plugin integrates directly into the Rollup build pipeline and runs on the final bundle, not on source files.
Common errors
error Error: [ECMA Version Validator] Unexpected token (1:5) ↓
cause The bundle contains syntax not valid for the target ECMAScript version. For example, arrow functions in an ES5 target.
fix
Either set ecmaVersion to a higher version (e.g., 2020) or use a transpiler like Babel before Rollup to transform the code.
error Error: Cannot find module 'rollup-plugin-ecma-version-validator' ↓
cause The package is not installed or is missing from node_modules.
fix
Run
npm install --save-dev rollup-plugin-ecma-version-validator. error TypeError: ecmaVersionValidator is not a function ↓
cause Default import was used instead of named import.
fix
Change import to
import { ecmaVersionValidator } from 'rollup-plugin-ecma-version-validator'. Warnings
gotcha The plugin only validates the final bundle output, not the source files. If you use code splitting or multiple outputs, each output will be validated separately, but the plugin must be applied per output config or globally. ↓
fix Ensure the plugin is included in the plugins array for the outputs you want to validate.
gotcha The default ecmaVersion is 5 (ES5), which is very restrictive. If your code uses modern syntax (async/await, arrow functions, etc.), it will fail validation unless you explicitly set ecmaVersion higher. ↓
fix Set ecmaVersion to the target version you actually need, like 2020 for ES2020.
deprecated The option 'acornOptions' is no longer supported; Acorn parsing is internal. Custom Acorn options cannot be passed. ↓
fix Remove acornOptions from the options object. Use ecmaVersion only.
breaking v0.2.0 removed support for Rollup 1.x. Peer dependency changed to rollup ^2.16.1 || ^3.x. ↓
fix Upgrade to Rollup ^2.16.1 or ^3.x. If stuck on Rollup 1.x, stay on v0.1.x.
gotcha The plugin does not handle dynamic imports or code splitting across multiple output files; each file is validated independently. If you use dynamic imports, the plugin may fail on the main chunk if it contains dynamic import() syntax not supported by the target ecmaVersion. ↓
fix Set ecmaVersion high enough to support dynamic imports (ES2020 or later) or disable validation for chunks that contain dynamic imports.
Install
npm install rollup-plugin-ecma-version-validator yarn add rollup-plugin-ecma-version-validator pnpm add rollup-plugin-ecma-version-validator Imports
- ecmaVersionValidator wrong
import ecmaVersionValidator from 'rollup-plugin-ecma-version-validator'correctimport { ecmaVersionValidator } from 'rollup-plugin-ecma-version-validator' - EcmaVersionValidatorOptions wrong
import { EcmaVersionValidatorOptions } from 'rollup-plugin-ecma-version-validator'correctimport type { EcmaVersionValidatorOptions } from 'rollup-plugin-ecma-version-validator' - plugin via require wrong
const ecmaVersionValidator = require('rollup-plugin-ecma-version-validator')correctconst { ecmaVersionValidator } = require('rollup-plugin-ecma-version-validator')
Quickstart
// rollup.config.js
import { ecmaVersionValidator } from 'rollup-plugin-ecma-version-validator';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
ecmaVersionValidator({
ecmaVersion: 5
})
]
};