@babel-register is not configurable when used with ES Modules (--experimental-modules)
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
Choose one: is this a bug report or feature request? Bug report
### Input Code
```js
import babelRegister from '@babel/register'
babelRegister({ extensions: '.xxx' })
```
### Babel/Babylon Configuration (.babelrc, package.json, cli command)
The specific config I'm using should not be relevant, but I'm providing it just in case.
```js
{
"plugins": [
"transform-class-properties",
[
"transform-react-jsx",
{
"pragma": "h",
"useBuiltIns": true
}
],
"transform-object-rest-spread"
]
}
```
### Expected Behavior
Invoking Node.js 8 LTS or Node.js 9 with the `--experimental-modules` command line flag enables built-in support for ES Modules. When this option is passed, the entry-point file must be an ES Module, which requires the use of `import` statements; `require` is not available. Using `import` on CommonJS modules is supported.
I expect that invoking the following code will change the babel-register configuration:
```bash
node --experimental-modules index.mjs
```
```js
// index.mjs
import babelRegister from '@babel/register'
babelRegister({ extensions: '.xxx' })
// babel-register should *not* transpile foo.mjs (because it has a .mjs extension)
import foo from './foo'
```
```js
// foo.mjs
console.log('blah')
```
### Current Behavior
The configuration stays unchanged even when following how the documentation says to configure `babel-register`.
### Possible Solution
I think the reason might be that module loading with ES Modules is async, while CommonJS is sync. Does `babel-register` assume that the function to configure will be called in the first tick?
### Context
Trying to using `babel-register` for server-side JSX support, while also using node's built-in ES Module support with the `--experimental-modules` flag.
### Your Environment
| software | version(s)
| ---------------- | -------
| Babel | @babel/core 7.0.0-beta.4; @babel-register 7.0.0-beta.5
| Babylon |
| node | 8.9.0
| npm | 5.5.1
| Operating System | macOS 10.13.1
Contributor guide
Assessment
This issue has not been assessed yet.