Registry / testing / karma-babel-preprocessor

karma-babel-preprocessor

JSON →
library8.0.2jsnpmunverified

Karma preprocessor to compile ES6+ on the fly with Babel. Version 8.0.2, stable, maintained as part of the Babel ecosystem. Requires @babel/core 7 as a peer dependency. Use with Babel presets to transpile modern JavaScript during test runs. Not a module bundler; for CommonJS you need a separate bundler like webpack or browserify. Key differentiator: seamless integration with Karma test runner, supports per-file Babel options via function properties.

npm install karma-babel-preprocessor
INSTALL
IMPORT
SIG · KARMA-BABEL-PREPRO
K
karma-babel-preprocessor
testingjavascriptv8.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babelPreprocessor
module.exports = function(config) { config.set({ babelPreprocessor: { options: { presets: ['@babel/preset-env'] } } }); };
module.exports = function(config) { config.set({ preprocessors: { '**/*.js': ['babel'] } }); };
Configuration is set via `babelPreprocessor` key in karma config. Wrong preprocessor pattern applies babel to all files including node_modules.
config.set({ preprocessors })
preprocessors: { 'src/**/*.js': ['babel'] }
preprocessors: { '**/*.js': ['babel'] }
Always limit preprocessor to source files only; applying to all files breaks third-party libraries.
babelPreprocessor.options
babelPreprocessor: { options: { presets: ['@babel/preset-env'], sourceMap: 'inline' }, filename: function(file) { return file.originalPath; } }
babelPreprocessor: { presets: ['@babel/preset-env'] }
Options must be nested inside `options` key. Directly setting presets at top level is not supported.

Installs the preprocessor and configures Karma to transpile source and test files with Babel presets.

npm install karma karma-babel-preprocessor @babel/core @babel/preset-env --save-dev // karma.conf.js module.exports = function(config) { config.set({ frameworks: ['jasmine'], files: [ 'src/**/*.js', 'test/**/*.js' ], preprocessors: { 'src/**/*.js': ['babel'], 'test/**/*.js': ['babel'] }, babelPreprocessor: { options: { presets: ['@babel/preset-env'], sourceMap: 'inline' } }, browsers: ['ChromeHeadless'] }); };
Debug
Known issues
breakingVersion 8.x drops support for Babel 6. Requires @babel/core 7 as peer dependency.
fix
Update to @babel/core 7 and use @babel/preset-env. If on Babel 6, stick with karma-babel-preprocessor@7.
affects: >=8.0.0
breakingVersion 7.x removed support for Babel 5. Requires babel-core 6.
fix
Use babel-preset-env and babel-core 6. For Babel 5, use karma-babel-preprocessor@6.
affects: >=7.0.0 <8.0.0
gotchaDo not preprocess all files (e.g., '**/*.js'). This includes node_modules and breaks third-party libraries like Jasmine.
fix
Limit preprocessor to specific paths: 'src/**/*.js', 'test/**/*.js'.
affects: >=1.0.0
gotchakarma-babel-preprocessor only transpiles ES modules to CommonJS; it does not resolve or bundle modules. You still need a module bundler like webpack or browserify.
fix
Use karma-webpack + babel-loader or karma-browserify + babelify for complete module bundling.
affects: >=1.0.0
deprecatedUse of babel-polyfill is deprecated in favor of @babel/polyfill (or better, core-js/regenerator-runtime).
fix
Replace 'babel-polyfill' with '@babel/polyfill' or include core-js and regenerator-runtime directly.
affects: >=8.0.0
Errors
Common errors & fixes
Module '@babel/core' has been externalized for browser compatibility, cannot be resolved in node_modules
Missing @babel/core dependency; or using karma-webpack with babel-loader which externalizes node_modules.
fix
Ensure @babel/core is installed: npm install @babel/core --save-dev
Error: Cannot find module '@babel/core'
@babel/core not installed or not in node_modules.
fix
Run: npm install @babel/core @babel/preset-env --save-dev
Babel presets must be an array of preset names
babelPreprocessor options not nested correctly; e.g., presets set at top level instead of inside options.
fix
Use: babelPreprocessor: { options: { presets: ['@babel/preset-env'] } }
Upgrade
Version history
8.0.2latest on npm
Audit
Dependencies
@babel/corerequiredpeer dependency required for transpilation
Agent activity
4 hits · last 30 days
node
4
Resources
karma-babel-preprocessor — npm install karma-babel-preprocessor · libregistry