title: Babel unexpected token import when running mocha tests
body: <p>The solutions offered in other related questions, such as including the proper presets (es2015) in .babelrc, are already implemented in my project.</p>
  
  <p>I have two projects (lets call them A and B) which both use ES6 module syntax.  In Project A, I'm importing Project B which is installed via npm and lives in the node_modules folder. When I run my test suite for Project A, I'm getting the error: </p>
  
  <blockquote>
    <p>SyntaxError: Unexpected token import</p>
  </blockquote>
  
  <p>Which is preceded by this alleged erroneous line of code from Project B:</p>
  
  <blockquote>
    <p>(function (exports, require, module, __filename, __dirname) { import
    createBrowserHistory from 'history/lib/createBrowserHistory';</p>
  </blockquote>
  
  <p>The iife appears to be something npm or possibly babel related since my source file only contains "import createBrowserHistory from 'history/lib/createBrowserHistory'; The unit tests in Project B's test suite runs fine, and if I remove Project B as a dependency from Project A, my test suite then (still using es6 imports for internal project modules) works just fine.</p>
  
  <p>Full Stack Trace:</p>
  
  <pre><code> SyntaxError: Unexpected token import
      at exports.runInThisContext (vm.js:53:16)
      at Module._compile (module.js:374:25)
      at Module._extensions..js (module.js:405:10)
      at Object.require.extensions.(anonymous function) [as .js] (/ProjectA/node_modules/babel-register/lib/node.js:138:7)
      at Module.load (module.js:344:32)
      at Function.Module._load (module.js:301:12)
      at Module.require (module.js:354:17)
      at require (internal/module.js:12:17)
      at Object.&lt;anonymous&gt; (actionCreators.js:4:17)
      at Module._compile (module.js:398:26)
      at loader (/ProjectA/node_modules/babel-register/lib/node.js:130:5)
      at Object.require.extensions.(anonymous function) [as .js] (/ProjectA/node_modules/babel-register/lib/node.js:140:7)
      at Module.load (module.js:344:32)
      at Function.Module._load (module.js:301:12)
      at Module.require (module.js:354:17)
      at require (internal/module.js:12:17)
      at Object.&lt;anonymous&gt; (/ProjectA/src/components/core/wrapper/wrapper.js:28:23)
      at Module._compile (module.js:398:26)
      at loader (/ProjectA/node_modules/babel-register/lib/node.js:130:5)
      at Object.require.extensions.(anonymous function) [as .js] (/ProjectA/node_modules/babel-register/lib/node.js:140:7)
      at Module.load (module.js:344:32)
      at Function.Module._load (module.js:301:12)
      at Module.require (module.js:354:17)
      at require (internal/module.js:12:17)
      at Object.&lt;anonymous&gt; (/ProjectA/src/components/core/wrapper/wrapperSpec.js:15:16)
      at Module._compile (module.js:398:26)
      at loader (/ProjectA/node_modules/babel-register/lib/node.js:130:5)
      at Object.require.extensions.(anonymous function) [as .js] (/ProjectA/node_modules/babel-register/lib/node.js:140:7)
      at Module.load (module.js:344:32)
      at Function.Module._load (module.js:301:12)
      at Module.require (module.js:354:17)
      at require (internal/module.js:12:17)
      at /ProjectA/node_modules/mocha/lib/mocha.js:219:27
      at Array.forEach (native)
      at Mocha.loadFiles (/ProjectA/node_modules/mocha/lib/mocha.js:216:14)
      at Mocha.run (/ProjectA/node_modules/mocha/lib/mocha.js:468:10)
      at Object.&lt;anonymous&gt; (/ProjectA/node_modules/mocha/bin/_mocha:403:18)
      at Module._compile (module.js:398:26)
      at Object.Module._extensions..js (module.js:405:10)
      at Module.load (module.js:344:32)
      at Function.Module._load (module.js:301:12)
      at Function.Module.runMain (module.js:430:10)
      at startup (node.js:141:18)
      at node.js:980:3
  </code></pre>
  
  <p>Here is my test command from package.json:</p>
  
  <pre><code>"test": "mocha --compilers js:babel-core/register '+(test|src)/**/*Spec.js'"
  </code></pre>
  
  <p>This StackOverflow post is similar but doesn't offer a solution for my use of the command line:
  <a href="https://stackoverflow.com/questions/31822593/import-a-module-from-node-modules-with-babel-but-failed">import a module from node_modules with babel but failed</a></p>