title: How to use Typescript as compiler in node-migrate
body: <p>To start, here's my migration script:</p>
  
  <pre><code>const bluebird = require("bluebird");
  const mongoose = require("mongoose");
  mongoose.Promise = bluebird;
  mongoose.connect("mongodb://localhost:27017/app", { useMongoClient: true    });
  
  const schema = {    
      uid: {  
          type: String,   
      },  
  
      parentID: { 
          type: String,   
      },  
  
      name: { 
          type: String,   
      },  
  
      displayName: {  
          type: String,   
      },  
  
      createdAt: {    
          type: Date, 
      },  
  
      modifiedAt: {   
          type: Date, 
      }   
  };  
  
  const FolderSchema = new mongoose.Schema(schema);   
  const FolderModel = mongoose.model("folders", FolderSchema);    
  
  
  // initial folders  
  const folders = [   
      { uid: "", parentID: "", name: "folder1", displayName: "Folder 1" },    
      { uid: "", parentID: "", name: "folder2", displayName: "Folder 2" },    
  ];  
  
  function up(next) { 
      const promises = [];    
      folders.map((folder, index) =&gt; {    
          promises.push(FolderModel.create(folder));  
      }); 
  
      bluebird.all(promises).then((res) =&gt; {  
          mongoose.connection.close();    
          next(); 
      }); 
  }   
  
  function down(next) {   
      const promises = [];    
      folders.map((folder, index) =&gt; {    
          promises.push(FolderModel.remove({ name: folder.name }));   
      }); 
  
      bluebird.all(promises).then((res) =&gt; {  
          next(); 
      }); 
  }   
  
  module.exports.up = up;
  module.exports.down = down;
  </code></pre>
  
  <p>I'm using <a href="https://github.com/tj/node-migrate" rel="nofollow noreferrer">node-migrate</a> for migration and in the Advanced migration creation part, it says:</p>
  
  <p>Lastly, if you want to use newer ECMAscript features, or language addons like TypeScript,
  for your migrations, you can use the compiler flag.</p>
  
  <p>But when I run the the script with <em>--compiler="ts:typescript"</em> it always throw an error even though I already have typescript installed.</p>
  
  <pre><code>    C:\Users\john\Workspace\app\node_modules\migrate\lib\register-compiler.js:12
    require(mod)({
                ^
  
  TypeError: require(...) is not a function
      at registerCompiler (C:\Users\john\Workspace\app\node_modules\migrate\lib\register-compiler.js:12:15)
      at Object.&lt;anonymous&gt; (C:\Users\john\Workspace\app\node_modules\migrate\bin\migrate-up:57:3)
      at Module._compile (module.js:635:30)
      at Object.Module._extensions..js (module.js:646:10)
      at Module.load (module.js:554:32)
      at tryModuleLoad (module.js:497:12)
      at Function.Module._load (module.js:489:3)
      at Function.Module.runMain (module.js:676:10)
      at startup (bootstrap_node.js:187:16)
      at bootstrap_node.js:608:3
  </code></pre>