Recently, I upgraded the devDependencies in one of my projects to the current versions. This included an update of karma-typescript-es6-transform
from version 1.0.2
to 1.0.3
.
Didn't sound dangorous. But afterwards my tests didn't run by karma any more.
Update 25-Feb-2018: with the latest version 1.0.4
of karma-typescript-es6-transform
the error doesn't occur anymore.
I just got:
18 02 2018 11:20:49.774:ERROR [karma]: Error: .../ionic-logging-service/node_modules/ionic-configuration-service/dist/index.js: Couldn't find preset "es2015" relative to directory ".../ionic-logging-service/node_modules/ionic-configuration-service/dist"
Transform function:
function (context, callback) {
if (!context.js) {
return callback(undefined, false);
}
if (isEs6(context.js.ast)) {
options.filename = context.filename;
log.debug("Transforming %s", options.filename);
try {
context.source = babel.transform(context.source, options).code;
context.js.ast = acorn.parse(context.source, { sourceType: "module" });
return callback(undefined, true);
}
catch (error) {
return callback(error, false);
}
}
else {
return callback(undefined, false);
}
}
at Transformer.handleError (.../ionic-logging-service/node_modules/karma-typescript/dist/bundler/transformer.js:108:19)
at .../ionic-logging-service/node_modules/karma-typescript/dist/bundler/transformer.js:89:27
at transform (.../ionic-logging-service/node_modules/karma-typescript-es6-transform/dist/transform.js:57:24)
at .../ionic-logging-service/node_modules/karma-typescript/dist/bundler/transformer.js:83:17
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
The most results on Google told me this were a problem that the newer versions of babel
would use babel-preset-env
instead of babel-preset-es2015
.
Apparently, something wanted to use the later one, but in my installed node modules was only babel-preset-env
, which is a dependency to karma-typescript-es6-transform@1.0.3
.
So I came up with 2 solutions:
- install
babel-preset-es2015
manually - tell
babel
to usebabel-preset-env
I preferred the second solution. Therefore I added to my karma.conf.js
the option:
karmaTypescriptConfig: {
bundlerOptions: {
transforms: [
require("karma-typescript-es6-transform")({
presets: [
["env"]
]
})
]
}
},
As often, it is enough to write a few characters to solve a problem. You only need to know the characters and the right place...
If you are interested in the whole solution, have a look a the aforementioned project.