<blockquote>
<p dir="auto">In order to encourage the use of CommonJS and ES6 modules, when exporting a default <code class="notranslate">export</code> <strong>with no other exports</strong> <code class="notranslate">module.exports</code> will be set in addition to <code class="notranslate">exports["default"].</code></p>
</blockquote>
<p dir="auto">I found this behavior to be counter-intuitive: it works… until you export more variables. Definitely unexpected :(</p>
<p dir="auto">This could be fixed by switching by having <code class="notranslate">module.exports = default</code> before other exports, added via <code class="notranslate">module.exports.doSomething = doSomething</code></p>
<p dir="auto">This sample code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default 1;
export const x = 2;"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-k">const</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Generates:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

Object.defineProperty(exports, &quot;__esModule&quot;, {
  value: true
});
exports[&quot;default&quot;] = 1;
var x = 2;
exports.x = x;"><pre class="notranslate"><span class="pl-s">"use strict"</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">"__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-s">"default"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span><span class="pl-kos">;</span>
<span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Which is fine.<br>
Now if we remove the named export:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default 1;"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-c1">1</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Generates:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

Object.defineProperty(exports, &quot;__esModule&quot;, {
  value: true
});
exports[&quot;default&quot;] = 1;
module.exports = exports[&quot;default&quot;];"><pre class="notranslate"><span class="pl-s">"use strict"</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">"__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-s">"default"</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-c1">1</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-s1">exports</span><span class="pl-kos">[</span><span class="pl-s">"default"</span><span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">The <code class="notranslate">module.exports</code> is overwritten by the default export.<br>
This still works fine if importing the module via <code class="notranslate">import</code> statements (due to the <code class="notranslate">interopRequireDefault</code> helper), but it is rather confusing and error-prone if importing the CJS module via <code class="notranslate">require()</code> calls.</p>
<p dir="auto">That is, sometimes the default export is returned directly by <code class="notranslate">require('module')</code>, other times you will need to access the <code class="notranslate">require('module').default</code> property, all depending on an arbitrary factor that may change anytime (adding/removing named exports), which causes a breaking change for all consumers.</p>