<p dir="auto">Filing this as a close duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="396935742" data-permission-text="Title is private" data-url="https://github.com/babel/babel/issues/9299" data-hovercard-type="issue" data-hovercard-url="/babel/babel/issues/9299/hovercard" href="https://github.com/babel/babel/issues/9299">#9299</a> because that issue is locked, and with the release of Node v12, the createRequireFromPath boilerplate has become more <a href="http://2ality.com/2019/04/nodejs-esm-impl.html#importing-commonjs-from-esm" rel="nofollow">widespread</a>, and it involves <code class="notranslate">import.meta.url</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {createRequireFromPath as createRequire} from 'module';
import {fileURLToPath as fromURL} from 'url';
const require = createRequire(fromURL(import.meta.url));"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-s1">createRequireFromPath</span> <span class="pl-k">as</span> <span class="pl-s1">createRequire</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'module'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-s1">fileURLToPath</span> <span class="pl-k">as</span> <span class="pl-s1">fromURL</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'url'</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">require</span> <span class="pl-c1">=</span> <span class="pl-en">createRequire</span><span class="pl-kos">(</span><span class="pl-en">fromURL</span><span class="pl-kos">(</span><span class="pl-k">import</span><span class="pl-kos">.</span><span class="pl-c1">meta</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">As a Babel end-user, I don't know how to work around the <code class="notranslate">SyntaxError: Cannot use 'import.meta' outside a module</code>, and leaving that issue open might allow someone more knowledgeable to offer a solution.</p>
<p dir="auto"><sub>I personally find it mildly infuriating when conversations are locked without any spam or abuse problems, because nether I nor others can add anything that might help each other. Sometimes the "final word" from the core team is less than intelligible to those new to the topic.</sub></p>
<p dir="auto">I am getting the following two type errors after switching to preset-env;</p>
<h3 dir="auto">Issue 1</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Duplicate declaration &quot;activities&quot; (This is an error on an internal node. Probably an internal error)"><pre class="notranslate"><code class="notranslate">Duplicate declaration "activities" (This is an error on an internal node. Probably an internal error)
</code></pre></div>
<p dir="auto">Related relevant code with the various (valid) declarations of <code class="notranslate">activities</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=".run((Page, Filters, moment, $store, $state, $transitions) =&gt; {
  $transitions.onEnter({to: 'bookings'}, transition =&gt; {
    const params = {};
    if (!params.activity) {
      const activities = transition.injector().get('activities');
      //...
    }
    //...
  });

  //Page setup
  $transitions.onSuccess({to: 'bookings'}, transition =&gt; {
    //...
    const activities = transition.injector().get('activities');
    //...
  });

  Page.defineOption('switchActivity', {
    async click() {
      //...
      const activities = await $store.activities.query();
      //...
    },
  });
});"><pre class="notranslate"><span class="pl-kos">.</span><span class="pl-en">run</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-v">Page</span><span class="pl-kos">,</span> <span class="pl-v">Filters</span><span class="pl-kos">,</span> <span class="pl-s1">moment</span><span class="pl-kos">,</span> <span class="pl-s1">$store</span><span class="pl-kos">,</span> <span class="pl-s1">$state</span><span class="pl-kos">,</span> <span class="pl-s1">$transitions</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-s1">$transitions</span><span class="pl-kos">.</span><span class="pl-en">onEnter</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">to</span>: <span class="pl-s">'bookings'</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">transition</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">params</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">params</span><span class="pl-kos">.</span><span class="pl-c1">activity</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">const</span> <span class="pl-s1">activities</span> <span class="pl-c1">=</span> <span class="pl-s1">transition</span><span class="pl-kos">.</span><span class="pl-en">injector</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'activities'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-c">//...</span>
    <span class="pl-kos">}</span>
    <span class="pl-c">//...</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-c">//Page setup</span>
  <span class="pl-s1">$transitions</span><span class="pl-kos">.</span><span class="pl-en">onSuccess</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">to</span>: <span class="pl-s">'bookings'</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">transition</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c">//...</span>
    <span class="pl-k">const</span> <span class="pl-s1">activities</span> <span class="pl-c1">=</span> <span class="pl-s1">transition</span><span class="pl-kos">.</span><span class="pl-en">injector</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'activities'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-c">//...</span>
  <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-v">Page</span><span class="pl-kos">.</span><span class="pl-en">defineOption</span><span class="pl-kos">(</span><span class="pl-s">'switchActivity'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
    <span class="pl-k">async</span> <span class="pl-en">click</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-c">//...</span>
      <span class="pl-k">const</span> <span class="pl-s1">activities</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">$store</span><span class="pl-kos">.</span><span class="pl-c1">activities</span><span class="pl-kos">.</span><span class="pl-en">query</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-c">//...</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">They are all defined in their own function scope, so perfectly valid.</p>
<h3 dir="auto">Issue 2</h3>
<p dir="auto"><code class="notranslate">Cannot read property '0' of null</code></p>
<p dir="auto">Related code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="      //Set relevant option
      if (last &amp;&amp; this.reminderOptions.some(o =&gt; o.value === last)) {
        this.booking.reminderTime = last;
      }
      else {
        this.booking.reminderTime = this.reminderOptions[0].value;
      }"><pre class="notranslate">      <span class="pl-c">//Set relevant option</span>
      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">last</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">reminderOptions</span><span class="pl-kos">.</span><span class="pl-en">some</span><span class="pl-kos">(</span><span class="pl-s1">o</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">o</span><span class="pl-kos">.</span><span class="pl-c1">value</span> <span class="pl-c1">===</span> <span class="pl-s1">last</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">booking</span><span class="pl-kos">.</span><span class="pl-c1">reminderTime</span> <span class="pl-c1">=</span> <span class="pl-s1">last</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span>
      <span class="pl-k">else</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">booking</span><span class="pl-kos">.</span><span class="pl-c1">reminderTime</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">reminderOptions</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">;</span>
      <span class="pl-kos">}</span></pre></div>
<p dir="auto">No idea why the latter error would be thrown as babel can't know what the value of <code class="notranslate">this.reminderOptions</code> will be at runtime, or whether it is <code class="notranslate">null</code>.</p>
<h3 dir="auto">Babel/Babylon Configuration (.babelrc, 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;env&quot;, {
      &quot;targets&quot;: {
        &quot;browsers&quot;: [&quot;chrome &gt;= 60&quot;]
      }
    }]
  ],
  &quot;plugins&quot;: [
    &quot;syntax-async-functions&quot;,
    &quot;transform-regenerator&quot;,
    &quot;angularjs-annotate&quot;
  ]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"env"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-s">"targets"</span>: <span class="pl-kos">{</span>
        <span class="pl-s">"browsers"</span>: <span class="pl-kos">[</span><span class="pl-s">"chrome &gt;= 60"</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-kos">,</span>
  <span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span>
    <span class="pl-s">"syntax-async-functions"</span><span class="pl-kos">,</span>
    <span class="pl-s">"transform-regenerator"</span><span class="pl-kos">,</span>
    <span class="pl-s">"angularjs-annotate"</span>
  <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">The code should compile and no errors should be thrown</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Error is thrown as described above.</p>
<h3 dir="auto">Context</h3>
<p dir="auto">Can't build, had to revert back to es2015</p>
<h3 dir="auto">Your Environment</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;babel-core&quot;: &quot;^6.26.0&quot;,
    &quot;babel-plugin-angularjs-annotate&quot;: &quot;^0.8.2&quot;,
    &quot;babel-plugin-syntax-async-functions&quot;: &quot;^6.13.0&quot;,
    &quot;babel-plugin-transform-regenerator&quot;: &quot;^6.26.0&quot;,
    &quot;babel-polyfill&quot;: &quot;^6.26.0&quot;,
    &quot;babel-preset-env&quot;: &quot;^1.6.1&quot;,"><pre class="notranslate"><code class="notranslate">    "babel-core": "^6.26.0",
    "babel-plugin-angularjs-annotate": "^0.8.2",
    "babel-plugin-syntax-async-functions": "^6.13.0",
    "babel-plugin-transform-regenerator": "^6.26.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.6.1",
</code></pre></div>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>node</td>
<td>8.9.4</td>
</tr>
<tr>
<td>npm</td>
<td>Yarn 1.3.2</td>
</tr>
<tr>
<td>Operating System</td>
<td>OS X</td>
</tr>
</tbody>
</table>