xlsx-template icon indicating copy to clipboard operation
xlsx-template copied to clipboard

Uncaught TypeError: this._factory is not a function

Open ronxbysu opened this issue 3 years ago • 2 comments

test('xls report file should be created again', async () => {

let values = {
  lastName: 'Тестов',
  firstName: 'Тест',
  middleName: 'Тестович',
};

const XlsxTemplate = require('xlsx-template');

// Load an XLSX file into memory
fs.readFile(path.join(__dirname, 'Book1.xlsx'), function(err, data) {

  // Create a template
  const template = new XlsxTemplate(data);

  // Replacements take place on first sheet
  const sheetNumber = 1;

  // Set up some placeholder values matching the placeholders in the template

  // Perform substitution
  template.substitute(sheetNumber, values);

  // Get binary data
  const generated = template.generate();

  fs.writeFileSync('B1.xlsx', generated, 'binary')

});

});

in Book1.xlsx - one simple string ${lastName} nothing more then run this test you get: Uncaught TypeError: this._factory is not a function

ronxbysu avatar May 08 '22 00:05 ronxbysu

Couple questions:

  • What's NodeJS version?
  • Are this is new test or existing one?

kant2002 avatar May 09 '22 04:05 kant2002

In the offline chat we discover that changing fs.readFile to fs.readFileSync at least unblock the issue. so far there no conclusive reason why issue happens.

I would speculate that when called inside async context this line produce some issues https://github.com/racker/node-elementtree/blob/master/lib/treebuilder.js#L8

I waiting for smallest @ronxbysu case and will start troubleshooting from this point

kant2002 avatar May 10 '22 11:05 kant2002