<p dir="auto">I have encountered something that's very likely a bug.<br>
In the same module, the transpiled code for <code class="notranslate">export ... from ...</code> appears before the transpiled code for <code class="notranslate">import ...</code> in the output.<br>
This scenario has already been asked <a href="http://discuss.babeljs.io/t/re-exports-hoisted-above-imports/773" rel="nofollow">here</a> - unfortunately without an answer.<br>
I think this is a bug because the 2 following snippets should be equivalent:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import foo from 'foo';
export { default as bar } from 'bar';"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">foo</span> <span class="pl-k">from</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">default</span> <span class="pl-k">as</span> <span class="pl-s1">bar</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import foo from 'foo';
import bar from 'bar';
export { bar }"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">foo</span> <span class="pl-k">from</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-s1">bar</span> <span class="pl-k">from</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">bar</span> <span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Input Code</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import foo from 'foo';
export { default as bar } from 'bar';"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">foo</span> <span class="pl-k">from</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">default</span> <span class="pl-k">as</span> <span class="pl-s1">bar</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">see the <a href="https://babeljs.io/repl/#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;code_lz=JYWwDg9gTgLgBAMwhRUIjgciRTBuAKAFMAPSWOAbzgBMiEBDAVwBt4GBnOAIwajgC-qdFl5R8QA&amp;debug=false&amp;circleciRepo=&amp;evaluate=true&amp;lineWrap=false&amp;presets=es2015%2Ces2016%2Ces2017%2Creact%2Cstage-0%2Cstage-2&amp;targets=&amp;version=6.26.0" rel="nofollow">REPL</a></p>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>

<p dir="auto">Part of my <code class="notranslate">package.json</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;devDependencies&quot;: {
    &quot;babel-eslint&quot;: &quot;^7.2.3&quot;,
    &quot;babel-plugin-transform-decorators-legacy&quot;: &quot;^1.3.4&quot;,
    &quot;babel-preset-react-native&quot;: &quot;^4.0.0&quot;,
    &quot;eslint&quot;: &quot;^4.6.1&quot;,
    &quot;eslint-plugin-react&quot;: &quot;^7.3.0&quot;,
    &quot;react-test-renderer&quot;: &quot;16.0.0-alpha.12&quot;
  },
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-native start&quot;,
    &quot;android&quot;: &quot;react-native run-android&quot;,
    &quot;ios&quot;: &quot;react-native run-ios&quot;,
  },
  &quot;dependencies&quot;: {
    &quot;immutable&quot;: &quot;^3.8.1&quot;,
    &quot;prop-types&quot;: &quot;^15.5.10&quot;,
    &quot;react&quot;: &quot;16.0.0-alpha.12&quot;,
    &quot;react-native&quot;: &quot;0.47&quot;,
    &quot;react-navigation&quot;: &quot;^1.0.0-beta.11&quot;,
    &quot;react-redux&quot;: &quot;^5.0.6&quot;,
    &quot;redux&quot;: &quot;^3.7.2&quot;,
    &quot;redux-logger&quot;: &quot;^3.0.6&quot;,
    &quot;redux-promise&quot;: &quot;^0.5.3&quot;,
    &quot;redux-thunk&quot;: &quot;^2.2.0&quot;
  }
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"devDependencies"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"babel-eslint"</span>: <span class="pl-s">"^7.2.3"</span><span class="pl-kos">,</span>
    <span class="pl-s">"babel-plugin-transform-decorators-legacy"</span>: <span class="pl-s">"^1.3.4"</span><span class="pl-kos">,</span>
    <span class="pl-s">"babel-preset-react-native"</span>: <span class="pl-s">"^4.0.0"</span><span class="pl-kos">,</span>
    <span class="pl-s">"eslint"</span>: <span class="pl-s">"^4.6.1"</span><span class="pl-kos">,</span>
    <span class="pl-s">"eslint-plugin-react"</span>: <span class="pl-s">"^7.3.0"</span><span class="pl-kos">,</span>
    <span class="pl-s">"react-test-renderer"</span>: <span class="pl-s">"16.0.0-alpha.12"</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-s">"scripts"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"start"</span>: <span class="pl-s">"react-native start"</span><span class="pl-kos">,</span>
    <span class="pl-s">"android"</span>: <span class="pl-s">"react-native run-android"</span><span class="pl-kos">,</span>
    <span class="pl-s">"ios"</span>: <span class="pl-s">"react-native run-ios"</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-s">"dependencies"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"immutable"</span>: <span class="pl-s">"^3.8.1"</span><span class="pl-kos">,</span>
    <span class="pl-s">"prop-types"</span>: <span class="pl-s">"^15.5.10"</span><span class="pl-kos">,</span>
    <span class="pl-s">"react"</span>: <span class="pl-s">"16.0.0-alpha.12"</span><span class="pl-kos">,</span>
    <span class="pl-s">"react-native"</span>: <span class="pl-s">"0.47"</span><span class="pl-kos">,</span>
    <span class="pl-s">"react-navigation"</span>: <span class="pl-s">"^1.0.0-beta.11"</span><span class="pl-kos">,</span>
    <span class="pl-s">"react-redux"</span>: <span class="pl-s">"^5.0.6"</span><span class="pl-kos">,</span>
    <span class="pl-s">"redux"</span>: <span class="pl-s">"^3.7.2"</span><span class="pl-kos">,</span>
    <span class="pl-s">"redux-logger"</span>: <span class="pl-s">"^3.0.6"</span><span class="pl-kos">,</span>
    <span class="pl-s">"redux-promise"</span>: <span class="pl-s">"^0.5.3"</span><span class="pl-kos">,</span>
    <span class="pl-s">"redux-thunk"</span>: <span class="pl-s">"^2.2.0"</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>


<p dir="auto">The behavior should be equivalent to</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import foo from 'foo';
import bar from 'bar';
export { bar }"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">foo</span> <span class="pl-k">from</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-s1">bar</span> <span class="pl-k">from</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">bar</span> <span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Currently the code gets executed as if it was written like this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export { default as bar } from 'bar';
import foo from 'foo';"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-kos">{</span> <span class="pl-s1">default</span> <span class="pl-k">as</span> <span class="pl-s1">bar</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'bar'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-s1">foo</span> <span class="pl-k">from</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><code class="notranslate">'bar'</code> is required before <code class="notranslate">'foo'</code> no matter what exactly is put between <code class="notranslate">export</code> and <code class="notranslate">from</code> (e.g. the problem also occurs for <code class="notranslate">export * from ...</code>).</p>
<h3 dir="auto">Context</h3>
<p dir="auto">I am exporting multiple moddules from an <code class="notranslate">index.js</code> file.<br>
All exports depend on some code that must have been run.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import &quot;./this_code_must_be_run_before_the_exports&quot;
export * from &quot;./first&quot;
export * from &quot;./second&quot;"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s">"./this_code_must_be_run_before_the_exports"</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./first"</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./second"</span></pre></div>
<h3 dir="auto">Your Environment</h3>
<p dir="auto">I am using babel with React Native.</p>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>latest (<a href="https://babeljs.io/repl/" rel="nofollow">https://babeljs.io/repl/</a>)</td>
</tr>
<tr>
<td>node</td>
<td>8.7.0</td>
</tr>
<tr>
<td>npm</td>
<td>5.4.2</td>
</tr>
<tr>
<td>Operating System</td>
<td>macOS 10.12.6</td>
</tr>
</tbody>
</table>
<h3 dir="auto">Input Code</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import &quot;babel-polyfill&quot;;

export {default as foo} from &quot;./foo&quot;; //Foo depends on the babel-polyfill"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s">"babel-polyfill"</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-kos">{</span><span class="pl-s1">default</span> <span class="pl-k">as</span> <span class="pl-s1">foo</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"./foo"</span><span class="pl-kos">;</span> <span class="pl-c">//Foo depends on the babel-polyfill</span></pre></div>
<p dir="auto"><a href="https://babeljs.io/repl/#?babili=false&amp;evaluate=true&amp;lineWrap=false&amp;presets=es2015%2Creact%2Cstage-2&amp;experimental=true&amp;loose=false&amp;spec=false&amp;code=import%20%22babel-polyfill%22%3B%0A%0Aexport%20%7Bdefault%20as%20foo%7D%20from%20%22.%2Ffoo%22%3B%20%2F%2FFoo%20depends%20on%20the%20babel-polyfill%0A" rel="nofollow">Example in REPL</a></p>
<h3 dir="auto">Babel Configuration (.bablerc, package.json, cli command)</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;presets&quot;: [&quot;es-2015&quot;]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span><span class="pl-s">"es-2015"</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>


<p dir="auto">The contents of the foo module should be exported on as foo on the current module</p>
<h3 dir="auto">Current Behavior</h3>


<p dir="auto">Fails with <code class="notranslate">ReferenceError: regeneratorRuntime is not defined</code><br>
The following code is generated by babel:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Object.defineProperty(exports, &quot;__esModule&quot;, {
  value: true
});
exports.foo = undefined;

var _foo = require(&quot;./foo&quot;);

Object.defineProperty(exports, &quot;foo&quot;, {
  enumerable: true,
  get: function get() {
    return _interopRequireDefault(_foo).default;
  }
});

require(&quot;babel-polyfill&quot;);

function _interopRequireDefault(obj) { return obj &amp;&amp; obj.__esModule ? obj : { default: obj }; }"><pre class="notranslate"><span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s">"__esModule"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">value</span>: <span class="pl-c1">true</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">undefined</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-s1">_foo</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"./foo"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s">"foo"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-en">get</span>: <span class="pl-k">function</span> <span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-en">_interopRequireDefault</span><span class="pl-kos">(</span><span class="pl-s1">_foo</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">default</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"babel-polyfill"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">_interopRequireDefault</span><span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-s1">obj</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">obj</span><span class="pl-kos">.</span><span class="pl-c1">__esModule</span> ? <span class="pl-s1">obj</span> : <span class="pl-kos">{</span> <span class="pl-c1">default</span>: <span class="pl-s1">obj</span> <span class="pl-kos">}</span><span class="pl-kos">;</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">The <code class="notranslate">require("./foo")</code> call gets hoisted above the <code class="notranslate">require("babel-polyfill")</code> call, and so regeneratorRuntime is not defined when the contents of the foo module runs.  I found this issue with babel-polyfill specifically, but it could manifest with any import that performs a side-effect, followed by an <code class="notranslate">export ... from</code> with a module that relies on that side-effect.</p>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">It seems like the the <code class="notranslate">export ... from</code> should cause the module to be imported in the same order that it would be imported if the export statement were replaced with an import statement.</p>
<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.4.14</td>
</tr>
<tr>
<td>node</td>
<td>4.4.4</td>
</tr>
<tr>
<td>npm</td>
<td>3.9.0</td>
</tr>
</tbody>
</table>