{"record":{"id":"42d8df514f145c7e","repo":"denoland/deno","slug":"err-missing-args-42d8df","errorCode":"ERR_MISSING_ARGS","errorMessage":"The \"options\" or \"port\" or \"path\" argument must be specified","messagePattern":"The \"options\" or \"port\" or \"path\" argument must be specified","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/net.ts","lineNumber":1629,"sourceCode":"  }\n}\nObjectSetPrototypeOf(Socket.prototype, Duplex.prototype);\nObjectSetPrototypeOf(Socket, Duplex);\n\nSocket.prototype.connect = function (...args) {\n  let normalized;\n\n  if (ArrayIsArray(args[0]) && args[0][normalizedArgsSymbol]) {\n    normalized = args[0];\n  } else {\n    normalized = _normalizeArgs(args);\n  }\n\n  const options = normalized[0];\n  const cb = normalized[1];\n\n  if (options.port === undefined && options.path == null) {\n    throw new ERR_MISSING_ARGS([\"options\", \"port\", \"path\"]);\n  }\n\n  if (netClientSocketChannel.hasSubscribers) {\n    netClientSocketChannel.publish({\n      socket: this,\n    });\n  }\n\n  if (this.write !== Socket.prototype.write) {\n    this.write = Socket.prototype.write;\n  }\n\n  if (this.destroyed) {\n    this._handle = null;\n    this._peername = undefined;\n    this._sockname = undefined;\n  }\n","sourceCodeStart":1611,"sourceCodeEnd":1647,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/net.ts#L1611-L1647","documentation":"`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.","triggerScenarios":"`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).","commonSituations":"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.","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."],"exampleFix":"// before\nsocket.connect({ host: 'db.internal' });\n\n// after\nsocket.connect({ host: 'db.internal', port: Number(process.env.DB_PORT ?? 5432) });","handlingStrategy":"validation","validationCode":"function connectOpts(opts) {\n  if (opts.port === undefined && (opts.path === undefined || opts.path === null)) {\n    throw new Error('connect needs options.port or options.path');\n  }\n  return opts;\n}\nsocket.connect(connectOpts({ host, port }));","typeGuard":"function hasConnectTarget(v: unknown): v is { port?: number; path?: string } & Record<string, unknown> {\n  if (typeof v !== 'object' || v === null) return false;\n  const o = v as Record<string, unknown>;\n  return typeof o.port === 'number' || typeof o.path === 'string';\n}","tryCatchPattern":"try {\n  socket.connect(opts, cb);\n} catch (err) {\n  if (err?.code === 'ERR_MISSING_ARGS') {\n    // config bug, not a runtime fault: report which field was missing\n    throw new Error(`connect target missing: ${JSON.stringify(opts)}`, { cause: err });\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["net","socket","connect","missing-argument","node-compat"],"backgroundTag":"missing-required-argument","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}