Issue 1:
Choose one: is this a bug report or feature request?

Bug report.

Summary

When attempting to import and re-export a TypeScript enum with @babel/preset-env in loose mode, Babel generates code with an undefined export that throws a TypeError at runtime. This issue appeared after upgrading @babel/preset-env from v7.0.0-beta.31 to v7.0.0-beta.32.

Some sample code is below, but see https://github.com/phyllisstein/babel-env-loose-mwe for a complete MWE.

Input Code

// src/some-enum/index.ts

export enum SomeEnum {
MY_NAME = 'MY_NAME',
YOUR_NAME = 'YOUR_NAME',
}

// src/enums.ts

import { SomeEnum } from './some-enum'

export { SomeEnum }

// src/index.ts

import { SomeEnum } from './enums'

const payload = { name: 'phyllisstein', type: SomeEnum.MY_NAME }

console.log(`You did the thing, ${ payload.name }!`)

v7.0.0-beta.31 Emitted JS

// lib/enums.js

"use strict";

exports.__esModule = true;
Object.defineProperty(exports, "SomeEnum", {
enumerable: true,
get: function () {
return _someEnum.SomeEnum;
}
});

var _someEnum = require("./some-enum");

v7.0.0-beta.32 Emitted JS

// lib/enums.js

"use strict";

exports.__esModule = true;
exports.SomeEnum = _someEnum.SomeEnum;

var _someEnum = require("./some-enum");

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
"presets": [
["@babel/env", {
"targets": {
"node": "current"
},
"loose": true
}],
"@babel/typescript"
]
}

Expected Behavior

I should be able to import the enum and run the code transpiled from src/index.ts successfully.

Current Behavior

Babel emits code that throws a TypeError at runtime:

💥

TypeError: Cannot read property 'SomeEnum' of undefined
at Object.<anonymous> (/Users/daniel/Repos/Personal/babel-env-loose-mwe/lib/enums.js:4:30)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/daniel/Repos/Personal/babel-env-loose-mwe/lib/index.js:3:14)
at Module._compile (module.js:635:30)

Possible Solution

Context

We use TypeScript's enums as action creator types in our React/Redux code. I noticed the issue when attempting to import the enum into a test module and make assertions with it.

Your Environment

software
version(s)

Babel
v7.0.0-beta.32

Babylon
N/A

node
v8.9.1

npm
v5.5.1

Operating System
macOS 10.13.2 (17C67b)

Issue 2:
Bug Report

Current Behavior

code split fail with preset-env modules:commonjs v7.5.4

Expected behavior/code

when modules: 'common' and plugin @babel/plugin-syntax-dynamic-import''; babel will tranfrom import(...) to require(...), then will cause code split fail

Babel Configuration (.babelrc, package.json, cli command)

module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: 'commonjs'
}
],
'@babel/preset-react'
],
plugins: [
'@babel/plugin-syntax-dynamic-import'
]
};

Environment

Babel version(s): v7.5.4

Node/npm version: v11.6.0/6.5.0-next.0

OS: [e.g. OSX 10.13.4, Windows 10] OSX

Monorepo: [e.g. yes/no/Lerna]no

How you are using Babel: [e.g. cli, register, loader] cli