title: ExcelJS writeFile not working: Uncaught TypeError: fs.createWriteStream is not a function
body: <p>I'm trying to export a formatted excel file using ExcelJS and the writeFile method simply isn't working. I get the following exception when I call the function:</p>
  
  <p><code>Uncaught TypeError: fs.createWriteStream is not a function</code></p>
  
  <p>My javascript is bundled using browserify.js. Here's my source code:</p>
  
  <p>index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;head&gt;
    &lt;title&gt;Test Excel JS&lt;/title&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="description" content=""&gt;
  
    &lt;link rel="stylesheet" href="app.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div&gt;
      &lt;label&gt;Test&lt;/label&gt;
      &lt;button onclick="test()"&gt;Test this Stuff and Check your console log&lt;/button&gt;
    &lt;/div&gt;
  
    &lt;script src="bundle.js"&gt;&lt;/script&gt;
    &lt;script&gt;
        var test = function(){
            writeFile();
        };
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>app.js (bundled by browserify into bundle.js)</p>
  
  <pre><code>'use strict';
  
  global.Excel = require('../node_modules/exceljs/dist/es5/exceljs.browser');
  
  global.isRowBold = function(excelRow){
      return excelRow.getCell('name').value === "Jeff";
  };
  
  global.getRowColor = function(excelRow){
      return excelRow.getCell('color').value;
  };
  
  global.getCellColor = function(excelRow, cell){
      return (excelRow.getCell('name').value === 'John' &amp;&amp; cell.value === 0)? 'orange' : excelRow.getCell('color').value;
  };
  
  global.getFont = function(isBold, color){
      return {
          name: 'Arial Black',
          color: color,
          family: 2,
          size: 14,
          bold: isBold
      };
  };
  
  global.getTestHeader = function(){
      return [
          {key: "id", header: "Id"},
          {key: "name", header: "Name", width: 32},
          {key: "color", header: "Color", width: 10}
      ];
  };
  
  global.getTestData = function(){
      return [
          {
              id: 0,
              name: "John",
              color: "green"
          },
          {
              id: 1,
              name: "Rehan",
              color: "blue"
          },
          {
              id: 2,
              name: "Jeff",
              color: "yellow"
          }
      ];
  };
  
  global.generateTestFile = function(){
      var workbook = new Excel.Workbook();
  
      workbook.creator = "Generated";
      workbook.lastModifiedBy = "Generated";
      workbook.created = new Date();
      workbook.modified = new Date();
  
      var worksheet = workbook.addWorksheet('Sheet 1');
  
      //Set Column Headers
      worksheet.columns = getTestHeader();
  
      //Add Rows
      var testData = getTestData();
      var length = testData.length;
      for(var i = 0; i &lt; length; i++){
          worksheet.addRow(testData[i]);
      }
  
      //Format Rows
      worksheet.eachRow(function(row, rowNumber){
          var isBold = isRowBold(row);
          row.eachCell(function(cell, colNumber){
              var cellColor = getCellColor(row, cell);
              cell.font = getFont(isBold, cellColor);
          });
      });
  
      //workbook.commit();
      return workbook;
  };
  
  global.writeFile = function(){
      var workbook = generateTestFile();
      workbook.xlsx.writeFile('./output/newtestfile.xlsx')
          .then(function() {
              console.log('Done Writing file');
          });
  };
  </code></pre>