parallax/jsPDF · error · TypeError

Failed to construct 'FileReader': Please use the 'new' opera

Error message

Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

What it means

Thrown by the Blob.js FileReader polyfill constructor when invoked as a plain function (FileReader()) rather than with `new`. The polyfill checks `this instanceof FileReader`; without `new`, `this` is the global/undefined and the check fails, mirroring native DOM behavior which requires construction with new.

Source

Thrown at src/libs/Blob.js:316

  File.prototype.constructor = File;

  if (Object.setPrototypeOf) Object.setPrototypeOf(File, Blob);
  else {
    try {
      File.__proto__ = Blob;
    } catch (e) {}
  }

  File.prototype.toString = function() {
    return "[object File]";
  };

  /********************************************************/
  /*                FileReader constructor                */
  /********************************************************/
  function FileReader() {
    if (!(this instanceof FileReader))
      throw new TypeError(
        "Failed to construct 'FileReader': Please use the 'new' operator, this DOM object constructor cannot be called as a function."
      );

    var delegate = document.createDocumentFragment();
    this.addEventListener = delegate.addEventListener;
    this.dispatchEvent = function(evt) {
      var local = this["on" + evt.type];
      if (typeof local === "function") local(evt);
      delegate.dispatchEvent(evt);
    };
    this.removeEventListener = delegate.removeEventListener;
  }

  function _read(fr, blob, kind) {
    if (!(blob instanceof Blob))
      throw new TypeError(
        "Failed to execute '" +
          kind +

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Always construct with new: var fr = new FileReader();.
  2. If you have a factory wrapper, ensure it uses new internally or uses Reflect.construct.
  3. Lint with a rule that flags missing new on known constructors.

Example fix

// before
var fr = FileReader();
// after
var fr = new FileReader();
Defensive patterns

Strategy: validation

Validate before calling

var fr = new FileReader();

Try / catch

try { var fr = new FileReader(); } catch (e) { if (/new operator/.test(e.message)) { fr = new FileReader(); } else throw e; }

Prevention

When it happens

Trigger: Calling var fr = FileReader(); instead of var fr = new FileReader();. Passing FileReader as a callback that drops the new operator; code written against an older non-class shim that allowed function-style invocation.

Common situations: Migrating from a shim that permitted function calls; copy-paste code missing the new keyword; minifiers/transforms that drop new in certain patterns.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/c5c25f5a78360213. Report an issue: GitHub.