denoland/deno · error · TypeError

Failed to construct 'Notification': 1 argument required…

Error message

Failed to construct 'Notification': 1 argument required, but only 0 present.

What it means

The Deno desktop runtime implements the Web Notifications API with `new Notification(title, options?)` and shows the notification immediately. Per WebIDL rules the title argument is required; calling the constructor with zero arguments throws this TypeError, matching the exact wording browsers produce.

Solutions

  1. Pass a title: `new Notification("Hello", options)` - it is coerced with String(), so any defined value works
  2. In wrapper functions, default the title: `new Notification(title ?? "Update")`
  3. Validate inputs before constructing when the title comes from user input or config

Example fix

// before
const n = new Notification();

// after
const n = new Notification(title ?? "Update", { icon: "/icon.png" });
Defensive patterns

Strategy: type-guard

Validate before calling

if (title === undefined || title === null) {
  throw new TypeError("Notification title is required");
}

Type guard

function isNotificationTitle(t: unknown): t is string {
  return typeof t === "string" && t.length > 0;
}

Prevention

When it happens

Trigger: Calling `new Notification()` with no arguments in the desktop runtime. Note the guard is `arguments.length < 1`, so passing an explicit undefined title does NOT throw (it becomes the string "undefined") - only zero arguments triggers it.

Common situations: Porting browser code where a helper sometimes omitted the title; copy-pasting an example that destructured options before the title; interactive tutorials constructing notifications before the user typed a title.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of denoland/deno@f7822238ca (2026-08-20). Data as JSON: /api/errors/440b584d7e0adc1d. Report an issue: GitHub.

Appendix: source

Thrown at cli/rt/desktop.rs:500

        return out;
      }
      return new TextEncoder().encode(decodeURIComponent(payload));
    } catch {
      return null;
    }
  }

  const NotificationPrototype = NotificationNative.prototype;
  Object.setPrototypeOf(NotificationPrototype, EventTarget.prototype);

  const notifications = new Map();
  // The Web Notifications API constructor is `new Notification(title, options?)`
  // and shows the notification immediately. The native constructor takes
  // a third arg for pre-decoded icon bytes so the icon URL → bytes step
  // happens on the JS side (sync data: URL decoding only).
  const Notification = function Notification(title, options) {
    if (arguments.length < 1) {
      throw new TypeError(
        "Failed to construct 'Notification': 1 argument required, but only 0 present.",
      );
    }
    const t = String(title);
    const opts = options ?? {};
    const iconBytes = decodeDataUrlSync(opts.icon);
    const instance = new NotificationNative(t, opts, iconBytes ?? undefined);
    if (instance.notificationId !== 0) {
      notifications.set(instance.notificationId, instance);
    } else {
      // Backend didn't show it (no support / failure). The native side
      // already emitted a NotificationError event; nothing to track here.
    }
    return instance;
  };
  Object.setPrototypeOf(Notification, NotificationNative);
  Object.setPrototypeOf(Notification.prototype, NotificationPrototype);
  Notification.prototype.constructor = Notification;

View on GitHub (pinned to f7822238ca)