<p dir="auto">babel-node repl works differently from compiled code + node regarding<br>
import. The ES6-way of importing works fine when I compile code with<br>
babel and run it with with the node binary. In babel-node I can't<br>
seem to import a node-module. The import doesn't throw any error, but<br>
when I try to use the module, I get ReferenceError. Details below.</p>
<p dir="auto">First, run npm install. Then start the repl:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="node_modules/.bin/babel-node"><pre class="notranslate"><code class="notranslate">node_modules/.bin/babel-node
</code></pre></div>
<p dir="auto">Now, try to make an ES6-import of our example lib (ramda):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import R from 'ramda'
R.identity(1)"><pre class="notranslate"><code class="notranslate">import R from 'ramda'
R.identity(1)
</code></pre></div>
<p dir="auto">This error occurs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="R.identity(1);
^
ReferenceError: R is not defined"><pre class="notranslate"><code class="notranslate">R.identity(1);
^
ReferenceError: R is not defined
</code></pre></div>
<p dir="auto">However, direct call to CommonJS/Node require works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const R = require('ramda')
R.identity(1)
-&gt; 1"><pre class="notranslate"><code class="notranslate">const R = require('ramda')
R.identity(1)
-&gt; 1
</code></pre></div>
<p dir="auto">But when I do the same thing import by compiling my ES6 code first,<br>
and then run it with node, everything works fine. The test code (test-module.js):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import R from 'ramda'

const retval = R.identity(1)
console.log(retval)"><pre class="notranslate"><code class="notranslate">import R from 'ramda'

const retval = R.identity(1)
console.log(retval)
</code></pre></div>
<p dir="auto">Compile and run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="node_modules/.bin/babel test-module.js --out-file test-module-compiled.js
node test-module-compiled.js
-&gt; 1"><pre class="notranslate"><code class="notranslate">node_modules/.bin/babel test-module.js --out-file test-module-compiled.js
node test-module-compiled.js
-&gt; 1
</code></pre></div>
<p dir="auto">I used node version v0.12.7 and babel 5.8.23 (the newest which I was able to npm install). Example code/project is here: <a href="https://github.com/auramo/babel-node-repl-issue">https://github.com/auramo/babel-node-repl-issue</a></p>
<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tony-kerz/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tony-kerz">@tony-kerz</a></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.2</li>
<li><strong>npm version:</strong> 3.9.5</li>
</ul>
<h3 dir="auto">Options</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="babel-node ./src/leak-test-async-simple.js"><pre class="notranslate"><code class="notranslate">babel-node ./src/leak-test-async-simple.js
</code></pre></div>
<h3 dir="auto">Input code</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import debug from 'debug'
import assert from 'assert'

const dbg = debug('app:leak-test-async')

async function run() {
  try {
    let idx = 0
    const thresh = 1e5
    const limit = 1e6
    while (idx &lt; limit) {
      idx++
      const record = await get()
      assert(record)
      if (idx % thresh == 0) {
        dbg('records-read=%o, heap-used=%o mb', idx, process.memoryUsage().heapUsed/1e6)
      }
    }
    dbg('successfully processed [%o] records', idx)
  }
  catch (caught) {
    dbg('connect: caught=%o', caught)
  }
}

async function get() {
  return {
    foo: 'foo',
    bar: 'bar'
  }
}

run()"><pre class="notranslate"><code class="notranslate">import debug from 'debug'
import assert from 'assert'

const dbg = debug('app:leak-test-async')

async function run() {
  try {
    let idx = 0
    const thresh = 1e5
    const limit = 1e6
    while (idx &lt; limit) {
      idx++
      const record = await get()
      assert(record)
      if (idx % thresh == 0) {
        dbg('records-read=%o, heap-used=%o mb', idx, process.memoryUsage().heapUsed/1e6)
      }
    }
    dbg('successfully processed [%o] records', idx)
  }
  catch (caught) {
    dbg('connect: caught=%o', caught)
  }
}

async function get() {
  return {
    foo: 'foo',
    bar: 'bar'
  }
}

run()
</code></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">memory leak (possibly duplicate of: <a href="https://phabricator.babeljs.io/T7240" rel="nofollow">https://phabricator.babeljs.io/T7240</a>)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  app:leak-test-async records-read=100000, heap-used=146.651808 mb +0ms
  app:leak-test-async records-read=200000, heap-used=278.423792 mb +942ms
  app:leak-test-async records-read=300000, heap-used=383.71728 mb +1s
  app:leak-test-async records-read=400000, heap-used=506.817272 mb +945ms
  app:leak-test-async records-read=500000, heap-used=634.425064 mb +935ms
  app:leak-test-async records-read=600000, heap-used=759.827616 mb +959ms
  app:leak-test-async records-read=700000, heap-used=902.615704 mb +973ms
  app:leak-test-async records-read=800000, heap-used=942.299272 mb +1s
  app:leak-test-async records-read=900000, heap-used=1071.199184 mb +1s
  app:leak-test-async records-read=1000000, heap-used=1121.771856 mb +2s
  app:leak-test-async successfully processed [1000000] records +1ms"><pre class="notranslate"><code class="notranslate">  app:leak-test-async records-read=100000, heap-used=146.651808 mb +0ms
  app:leak-test-async records-read=200000, heap-used=278.423792 mb +942ms
  app:leak-test-async records-read=300000, heap-used=383.71728 mb +1s
  app:leak-test-async records-read=400000, heap-used=506.817272 mb +945ms
  app:leak-test-async records-read=500000, heap-used=634.425064 mb +935ms
  app:leak-test-async records-read=600000, heap-used=759.827616 mb +959ms
  app:leak-test-async records-read=700000, heap-used=902.615704 mb +973ms
  app:leak-test-async records-read=800000, heap-used=942.299272 mb +1s
  app:leak-test-async records-read=900000, heap-used=1071.199184 mb +1s
  app:leak-test-async records-read=1000000, heap-used=1121.771856 mb +2s
  app:leak-test-async successfully processed [1000000] records +1ms
</code></pre></div>