Could someone explain why babel compiles the following:
import {resolve} from "path";
export const exportedConst = "value";
to:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.exportedConst = undefined;
var _path = require("path");
var exportedConst = exports.exportedConst = "value";
and if I exported exportedConst without importing any other modules:
export const exportedConst = "value";
it compiles it to:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var exportedConst = exports.exportedConst = "value";
Why does it produce this line? exports.exportedConst = undefined;
and export it like this
var exportedConst = exports.exportedConst = "value";
this causes the IDE to see two exports
Maybe this is intelliJ problem, but it made me think about why babel does it this way.
I am using:
- nodejs :v8.5.0
- babel-cli : 6.26.0 (babel-core 6.26.0)
- babel-preset-env: 1.6.1
or if you want to reproduce it locally, here is a quick one-line command
mkdir stackoverflow-questin && cd stackoverflow-questin && npm init -y && npm install babel-cli babel-preset-env && echo 'import {resolve} from "path";\nexport const exportedConst = "value";' > index.js && npx babel index.js --out-file index.compiled.js --presets=env
