karma-es6-module-preprocessor
raw JSON → 0.2.0 verified Fri May 01 auth: no javascript deprecated
A Karma preprocessor that compiles ES6 module syntax (import/export) to ES5 using the es6-module-transpiler. Version 0.2.0 is the latest and appears to be unmaintained since 2014. It integrates with Karma test runner to transpile ES6 modules on the fly during testing. Note that the es6-module-transpiler project itself is deprecated in favor of Babel or TypeScript. This preprocessor is specific to the es6-module-transpiler and does not support newer transpilers like Babel. For modern projects, use karma-babel-preprocessor instead.
Common errors
error Module "es6-module-transpiler" not found ↓
cause The es6-module-transpiler is not installed as a dependency and this preprocessor depends on it.
fix
Install es6-module-transpiler as a devDependency: npm install es6-module-transpiler --save-dev
error No provider for "framework:karma-es6-module-preprocessor"! ↓
cause The plugin is listed in karma.conf.js with an incorrect name or not installed.
fix
Add 'karma-es6-module-preprocessor' to plugins array and ensure it is installed.
error TypeError: Cannot read property 'transpile' of undefined ↓
cause The es6-module-transpiler has not been found or initialization failed.
fix
Ensure es6-module-transpiler is installed and the path is correct.
Warnings
deprecated The es6-module-transpiler project is deprecated and no longer maintained. This preprocessor relies on an outdated transpiler. ↓
fix Migrate to karma-babel-preprocessor with appropriate Babel presets for ES6 modules.
gotcha Preprocessor name must be 'es6' in preprocessors config, not 'es6-module' or 'karma-es6-module-preprocessor'. ↓
fix Use 'es6' as the preprocessor name in the preprocessors object.
gotcha Karma plugins must include the full plugin name prefixed with 'karma-' if using short names. ↓
fix Set plugins: ['karma-es6-module-preprocessor'] in karma.conf.js.
breaking This plugin only supports Karma >=0.12.0. Older versions are incompatible. ↓
fix Upgrade Karma to version 0.12.0 or later.
Install
npm install karma-es6-module-preprocessor yarn add karma-es6-module-preprocessor pnpm add karma-es6-module-preprocessor Imports
- default (plugin) wrong
plugins: ['es6-module-preprocessor']correctplugins: ['karma-es6-module-preprocessor'] in karma.conf.js - preprocessor configuration wrong
preprocessors: { '**/*.js': ['es6-module'] }correctpreprocessors: { '**/*.js': ['es6'] } - CommonJS require wrong
var es6ModulePreprocessor = require('karma-es6-module-preprocessor').default;correctvar es6ModulePreprocessor = require('karma-es6-module-preprocessor');
Quickstart
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
plugins: ['karma-es6-module-preprocessor', 'karma-jasmine', 'karma-chrome-launcher'],
preprocessors: {
'**/*.js': ['es6']
},
files: [
'src/**/*.js',
'test/**/*.test.js'
],
browsers: ['ChromeHeadless'],
singleRun: true
});
};