<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
I upgraded to Babel 7.4.0 and core-js 3.<br>
I need to include some global Polyfills due to dependencies requiring them (for example React requires <code class="notranslate">Symbol</code>).<br>
I am using <code class="notranslate">useBuiltIns: "usage"</code> in my <code class="notranslate">env</code> config.</p>
<p dir="auto">Many polyfills end up being duplicated in my Webpack bundle because they get imported once from <code class="notranslate">core-js@3</code> due to my globally-polluting imports, and once again from <code class="notranslate">core-js-pure@3</code> from the <code class="notranslate">preset-env</code> imports.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/42070/54722378-b232d780-4b64-11e9-816b-28681d402c56.png"><img src="https://user-images.githubusercontent.com/42070/54722378-b232d780-4b64-11e9-816b-28681d402c56.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Expected behavior/code</strong><br>
I am not really sure what the expected behaviour would be here, but I expect my bundle to now grow in size because I am using <code class="notranslate">core-js@3</code>.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="presets = [
  &quot;@babel/preset-typescript&quot;,
  &quot;@babel/preset-react&quot;,
  [
    &quot;@babel/preset-env&quot;,
    {
      useBuiltIns: &quot;usage&quot;,
      corejs: 3,
    },
  ],
]

plugins = [
  &quot;@babel/plugin-syntax-dynamic-import&quot;,
  &quot;@babel/plugin-proposal-object-rest-spread&quot;,
  &quot;@babel/plugin-proposal-class-properties&quot;,
  [&quot;@babel/plugin-transform-runtime&quot;, { regenerator: false, corejs: 3 }],
]

module.exports = { presets, plugins }"><pre class="notranslate"><span class="pl-s1">presets</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span>
  <span class="pl-s">"@babel/preset-typescript"</span><span class="pl-kos">,</span>
  <span class="pl-s">"@babel/preset-react"</span><span class="pl-kos">,</span>
  <span class="pl-kos">[</span>
    <span class="pl-s">"@babel/preset-env"</span><span class="pl-kos">,</span>
    <span class="pl-kos">{</span>
      <span class="pl-c1">useBuiltIns</span>: <span class="pl-s">"usage"</span><span class="pl-kos">,</span>
      <span class="pl-c1">corejs</span>: <span class="pl-c1">3</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-s1">plugins</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span>
  <span class="pl-s">"@babel/plugin-syntax-dynamic-import"</span><span class="pl-kos">,</span>
  <span class="pl-s">"@babel/plugin-proposal-object-rest-spread"</span><span class="pl-kos">,</span>
  <span class="pl-s">"@babel/plugin-proposal-class-properties"</span><span class="pl-kos">,</span>
  <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-transform-runtime"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">regenerator</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span> <span class="pl-c1">corejs</span>: <span class="pl-c1">3</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
<span class="pl-kos">]</span>

<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span> presets<span class="pl-kos">,</span> plugins <span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): 7.4.0</li>
<li>Node/npm version: 11.11.0 / 6.7.0</li>
<li>OS: OSX 10.14.2</li>
<li>Monorepo: no</li>
<li>How you are using Babel: <code class="notranslate">loader</code></li>
</ul>
<blockquote>
<p dir="auto">Issue originally made by @skorlir</p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> 6.10.1</li>
<li><strong>Node version:</strong> 6.2.0</li>
<li><strong>npm version:</strong> 3.8.9</li>
</ul>
<h3 dir="auto">Description</h3>
<p dir="auto">See [[ https://github.com/skorlir/babel-bug-custom-errors | minimal reproduction ]] on GitHub. With a very basic babel setup, if you compile code that looks like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class RequiredError extends Error {
  constructor (requiredField, actualValue) {
    super(`[validator error]: ${requiredField} is required but got ${actualValue}.`)
  }
}"><pre class="notranslate"><code class="notranslate">class RequiredError extends Error {
  constructor (requiredField, actualValue) {
    super(`[validator error]: ${requiredField} is required but got ${actualValue}.`)
  }
}
</code></pre></div>
<p dir="auto">you get resulting ES5 that, although it imports correctly in the Node REPL, will not work with <code class="notranslate">instanceof</code>.</p>
<p dir="auto">Here are reproduction commands (from the root directory of the minimum reproduction repo):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ babel app/support/errors.js &gt; errors.js
$ node
&gt; const RequiredError = require('./errors').RequiredError
undefined
&gt; try { throw new RequiredError() } catch (e) { e instanceof RequiredError }
false
&gt;"><pre class="notranslate"><code class="notranslate">$ babel app/support/errors.js &gt; errors.js
$ node
&gt; const RequiredError = require('./errors').RequiredError
undefined
&gt; try { throw new RequiredError() } catch (e) { e instanceof RequiredError }
false
&gt;
</code></pre></div>
<p dir="auto">Note that TypeScript compiles this correctly. If I change the extension of the file from js to ts (<code class="notranslate">mv app/support/errors.js app/support/errors.ts</code>), and then run <code class="notranslate">tsc -m commonjs --outDir . app/support/errors.ts</code>, the output file works correctly when required into the Node REPL and used exactly as above.</p>
<p dir="auto">Also note that there is a failing test case already written in the minimum reproduction. All you need to do to run it is run <code class="notranslate">npm i &amp;&amp; npm test</code> as it states in the README.</p>