denoland/deno · error · TypeError
ERR_MISSING_ARGS
ERR_MISSING_ARGS
Error message
The "options" or "port" or "path" argument must be specified
What it means
`Socket.prototype.connect()` requires a TCP `port` or an IPC `path` in the normalized options. The polyfill throws ERR_MISSING_ARGS when `options.port === undefined` and `options.path` is null or undefined. This check runs before any other connect logic, so host, family, or fd alone cannot satisfy it.
Source
Thrown at ext/node/polyfills/net.ts:1629
}
}
ObjectSetPrototypeOf(Socket.prototype, Duplex.prototype);
ObjectSetPrototypeOf(Socket, Duplex);
Socket.prototype.connect = function (...args) {
let normalized;
if (ArrayIsArray(args[0]) && args[0][normalizedArgsSymbol]) {
normalized = args[0];
} else {
normalized = _normalizeArgs(args);
}
const options = normalized[0];
const cb = normalized[1];
if (options.port === undefined && options.path == null) {
throw new ERR_MISSING_ARGS(["options", "port", "path"]);
}
if (netClientSocketChannel.hasSubscribers) {
netClientSocketChannel.publish({
socket: this,
});
}
if (this.write !== Socket.prototype.write) {
this.write = Socket.prototype.write;
}
if (this.destroyed) {
this._handle = null;
this._peername = undefined;
this._sockname = undefined;
}
View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Pass `port` (number) or `path` (IPC socket path) in the connect options.
- Give environment-derived ports a fallback: `Number(process.env.PORT ?? 8080)`.
- Validate the options object for port/path before calling connect.
- For already-open file descriptors, construct with `new net.Socket({ fd })` instead of calling connect.
Example fix
// before
socket.connect({ host: 'db.internal' });
// after
socket.connect({ host: 'db.internal', port: Number(process.env.DB_PORT ?? 5432) }); Defensive patterns
Strategy: validation
Validate before calling
function connectOpts(opts) {
if (opts.port === undefined && (opts.path === undefined || opts.path === null)) {
throw new Error('connect needs options.port or options.path');
}
return opts;
}
socket.connect(connectOpts({ host, port })); Type guard
function hasConnectTarget(v: unknown): v is { port?: number; path?: string } & Record<string, unknown> {
if (typeof v !== 'object' || v === null) return false;
const o = v as Record<string, unknown>;
return typeof o.port === 'number' || typeof o.path === 'string';
} Try / catch
try {
socket.connect(opts, cb);
} catch (err) {
if (err?.code === 'ERR_MISSING_ARGS') {
// config bug, not a runtime fault: report which field was missing
throw new Error(`connect target missing: ${JSON.stringify(opts)}`, { cause: err });
}
throw err;
} Prevention
- Centralize connect option building in one function that requires port or path.
- Default env-derived ports: Number(process.env.PORT ?? 8080).
- Fail fast at startup on missing config instead of at connect time.
When it happens
Trigger: `socket.connect({ host: 'db.internal' })` with no port; `socket.connect({})`; `socket.connect({ port: undefined })` from a missing config value; `socket.connect({ fd: 3 })` — connect does not accept fd as its target (fd belongs to the constructor).
Common situations: A port read from `process.env.PORT` or a config file that is missing in one environment. Platform-conditional code that sets `path` only on Linux but runs on macOS too. Refactors that rename or drop the port field.
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
- ERR_INVALID_ARG_VALUE
- EPIPE
- Invalid port (expected number): ${maybePort}
- ERR_FS_CP_SOCKET
- ERR_HTTP_SOCKET_ASSIGNED
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/42d8df514f145c7e.
Report an issue: GitHub.