Transforms default import into namespace import (for libs).
import apollo from "apollo-server";
transform to
import apollo__DEFAULT__, * as apollo__NAMESPACE__ from "apollo-server";
const apollo = apollo__DEFAULT__ || apollo__NAMESPACE__;
Node v. 13.2.0 intorduced support of ES modules, but tools like jest use its own require and use babel for support esm. Native modules import commonjs only with default import, but babel uses named import for libs and it all conflicts. This plugin solves this problem.
npm i --save-dev babel-plugin-transform-default-import
.babelrc
{
"plugins": ["transform-default-import", {
"default": "__DEFAULT__",
"namespace": "__NAMESPACE__",
"hybrid": true
}]
}
{
"babel": {
"plugins": ["transform-default-import", {
"default": "__DEFAULT__",
"namespace": "__NAMESPACE__",
"hybrid": true
}]
}
}