title: Export es6 class in Babel - Cannot find module
body: <h3>I have seen these two answers on SO:</h3>
  
  <p><a href="https://stackoverflow.com/questions/29353728/exporting-a-class-with-es6-babel">Exporting a class with ES6 (Babel)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/29337966/trying-to-export-a-class-as-a-module-es6-babel">Trying to export a class as a module ES6 babel</a></p>
  
  <p>I am not using Browserify, just Gulp and Node, just wanted to preface. </p>
  
  <hr>
  
  <h3>File/Folder Structure:</h3>
  
  <p>./</p>
  
  <p>./gulpfile.js</p>
  
  <p>./_GULP</p>
  
  <p>./_GULP/main_config.es6</p>
  
  <p>./_GULP/_classes/Gcfg.es6</p>
  
  <hr>
  
  <h3>Question Setup</h3>
  
  <p>I am exporting a class <code>Gcfg.es6</code> file, like so:</p>
  
  <pre><code>export default class Gcfg {
     constructor() {
          this.rootDir = './';
          this.latestDir = './_LATEST/';
          this.srcFolder = './_SRC/';
          ...
     }
  
      getSrcDir(dir="") {
          return this.srcFolder + dir;
      }
      ...
  }
  </code></pre>
  
  <p>In <code>main_config.es6</code> I am trying to import:</p>
  
  <pre><code>import Gcfg from '_classes/Gcfg';
  </code></pre>
  
  <p><em>Following this GitHub post:</em></p>
  
  <p><a href="https://github.com/babel/babel/issues/849" rel="noreferrer">https://github.com/babel/babel/issues/849</a></p>
  
  <p>I assumed I was doing it all correctly. I am using WebStorm and have a "File Watcher" setup to run Babel on save of a .es6 file. I am not doing anything fancy there, the only optional flags I am using are:</p>
  
  <p><code>--source-maps</code> and <code>--out-file $FileNameWithoutExtension$.js $FilePath$</code> </p>
  
  <p>$FileNameWithoutExtension$.js is a WebStorm application variables and just is the file being loaded by the watcher and $FilePath$ is the absolute path to the file. </p>
  
  <p>So the command looks like this (I believe I actually do not see it executed):</p>
  
  <p><code>babel --source-maps --out-file main_config.js ./_GULP/</code> etc for the other files...</p>
  
  <p>All files are processed fine by babel I believe. I see the exports and requires in the generated JS. </p>
  
  <h2><strong>tl;dr</strong></h2>
  
  <p>In <code>gulpfile.js</code> I am doing:</p>
  
  <p><code>gCfg = require('./_GULP/main_config');</code> &lt;- this require works!</p>
  
  <p>However, when I try to run GULP it immediately fails and in the console I get:</p>
  
  <pre><code>Error: Cannot find module '_classes/Gcfg'
  at Function.Module._resolveFilename (module.js:336:15)
  at Function.Module._load (module.js:286:25)
  at Module.require (module.js:365:17)
  at require (module.js:384:17)
  at Object.&lt;anonymous&gt; (/Users/xxx/xxx/xxx/xxx/xxx/_GULP/main_config.js:9:20)
  at Module._compile (module.js:434:26)
  at Object.Module._extensions..js (module.js:452:10)
  at Module.load (module.js:355:32)
  at Function.Module._load (module.js:310:12)
  at Module.require (module.js:365:17)
  at require (module.js:384:17)
  </code></pre>
  
  <h3>The Question</h3>
  
  <p>Why am I unable to export the class in <code>Gcfg.es6</code> and import it into <code>main.es6</code> using es6 import/export? Is there a polyfill needed (I am loading bable/polyfill)? Is it that I have <code>_</code>'s in my path? I have just been thrashing on this for too long. </p>
  
  <p>Thanks!</p>