denoland/deno · error · TypeError

ERR_INVALID_ARG_VALUE

ERR_INVALID_ARG_VALUE

Error message

The argument 'address' is invalid. Received ${address}

What it means

Before doing reverse resolution, dns.lookupService verifies the address with isIP() and throws ERR_INVALID_ARG_VALUE when isIP(address) === 0 — i.e. the argument is not a literal IPv4/IPv6 address. Hostnames are not accepted here; lookupService expects an already-resolved IP.

Source

Thrown at ext/node/polyfills/dns.ts:358

  this.callback!(err, hostname, service);
}

function lookupService(
  address: string,
  port: number,
  callback: (
    err: ErrnoException | null,
    hostname?: string,
    service?: string,
  ) => void,
): GetNameInfoReqWrap {
  if (arguments.length !== 3) {
    throw new ERR_MISSING_ARGS("address", "port", "callback");
  }

  if (isIP(address) === 0) {
    throw new ERR_INVALID_ARG_VALUE("address", address);
  }

  port = validatePort(port);

  validateFunction(callback, "callback");

  const req = new GetNameInfoReqWrap();
  req.callback = callback;
  req.address = address;
  req.port = port;
  req.oncomplete = onlookupservice;

  const errCode = cares.getnameinfo(req, address, port);
  if (errCode) {
    throw dnsException(errCode, "getnameinfo", address);
  }

  return req;

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Resolve first: dns.lookup(hostname, (e, { address }) => dns.lookupService(address, port, cb))
  2. Guard with net.isIP(address) !== 0 before calling
  3. Trim/normalize the string — surrounding whitespace makes a valid literal invalid

Example fix

// before
dns.lookupService('localhost', 80, cb); // not an IP literal -> throws

// after
dns.lookup('localhost', (err, { address }) => {
  if (err) throw err;
  dns.lookupService(address, 80, cb);
});
Defensive patterns

Strategy: validation

Validate before calling

const { isIP } = require('node:net');
if (isIP(String(address).trim()) === 0) {
  // resolve hostnames first, or reject
  return dns.lookup(address, (e, { address: ip }) => dns.lookupService(ip, port, cb));
}
dns.lookupService(address, port, cb);

Type guard

const isIpLiteral = (s) => net.isIP(String(s ?? '')) !== 0;

Try / catch

catch (e) { if (e?.code === 'ERR_INVALID_ARG_VALUE') return cb(null); /* skip non-IP peers */ throw e; }

Prevention

When it happens

Trigger: dns.lookupService('localhost', 80, cb); dns.lookupService('example.com', 443, cb); malformed literals like '192.168.1' or 'fe80::1%eth0 ' (whitespace).

Common situations: Feeding request remote addresses that are actually hostnames in test setups; using req.socket.remoteAddress output after it became undefined and stringified to 'undefined'; proxies passing Host header values.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/4089d4ba7469e867. Report an issue: GitHub.