title: Why doesn't instanceof work on instances of Error subclasses under babel-node?
body: <p>I am seeing that the <code>instanceof</code> operator doesn't work on instances of <code>Error</code> subclasses, when running under <a href="https://babeljs.io/docs/usage/cli/#babel-node" rel="noreferrer">babel-node</a> version 6.1.18/Node version 5.1.0 on OS X. Why is this? The same code works well in the browser, try my <a href="https://jsfiddle.net/rvmmv9g0/" rel="noreferrer">fiddle</a> for an example.</p>
  <p>The following code outputs <code>true</code> in the browser, whereas under babel-node it's false:</p>
  <pre><code>class Sub extends Error {
  }
  
  let s = new Sub()
  console.log(`The variable 's' is an instance of Sub: ${s instanceof Sub}`)
  </code></pre>
  <p>I can only imagine this being due to a bug in babel-node, since <code>instanceof</code> works for other base classes than <code>Error</code>.</p>
  <h2>.babelrc</h2>
  <pre><code>{
    &quot;presets&quot;: [&quot;es2015&quot;]
  }
  </code></pre>
  <h2>Compiled Output</h2>
  <p>This is the JavaScript compiled by babel 6.1.18:</p>
  <pre><code>'use strict';
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(&quot;Cannot call a class as a function&quot;); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(&quot;this hasn't been initialised - super() hasn't been called&quot;); } return call &amp;&amp; (typeof call === &quot;object&quot; || typeof call === &quot;function&quot;) ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== &quot;function&quot; &amp;&amp; superClass !== null) { throw new TypeError(&quot;Super expression must either be null or a function, not &quot; + typeof superClass); } subClass.prototype = Object.create(superClass &amp;&amp; superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  var Sub = (function (_Error) {
    _inherits(Sub, _Error);
  
    function Sub() {
      _classCallCheck(this, Sub);
  
      return _possibleConstructorReturn(this, Object.getPrototypeOf(Sub).apply(this, arguments));
    }
  
    return Sub;
  })(Error);
  
  var s = new Sub();
  console.log('The variable \'s\' is an instance of Sub: ' + (s instanceof Sub));
  </code></pre>