{"record":{"id":"1f70b697b2cb44e4","repo":"denoland/deno","slug":"err-console-writable-stream","errorCode":"ERR_CONSOLE_WRITABLE_STREAM","errorMessage":"Console expects a writable stream instance for stdout","messagePattern":"Console expects a writable stream instance for stdout","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/console/constructor.mjs","lineNumber":156,"sourceCode":"  if (!options || typeof options.write === \"function\") {\n    options = {\n      stdout: options,\n      stderr: arguments[1],\n      ignoreErrors: arguments[2],\n    };\n  }\n\n  const {\n    stdout,\n    stderr = stdout,\n    ignoreErrors = true,\n    colorMode = \"auto\",\n    inspectOptions,\n    groupIndentation,\n  } = options;\n\n  if (!stdout || typeof stdout.write !== \"function\") {\n    throw new ERR_CONSOLE_WRITABLE_STREAM(\"stdout\");\n  }\n  if (!stderr || typeof stderr.write !== \"function\") {\n    throw new ERR_CONSOLE_WRITABLE_STREAM(\"stderr\");\n  }\n\n  if (typeof colorMode !== \"boolean\" && colorMode !== \"auto\") {\n    // Match Node: reason lists the accepted values (see\n    // lib/internal/console/constructor.js).\n    throw new ERR_INVALID_ARG_VALUE(\n      \"colorMode\",\n      colorMode,\n      \"must be one of: 'auto', true, false\",\n    );\n  }\n\n  if (groupIndentation !== undefined) {\n    validateInteger(\n      groupIndentation,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/console/constructor.mjs#L138-L174","documentation":"The Node-compatible Console class (require('node:console').Console, the options-object constructor) builds a console around streams you supply. options.stdout must be a writable stream - an object with a .write function. ERR_CONSOLE_WRITABLE_STREAM is thrown at construction when stdout is missing or lacks .write. Console accepts only Node-style streams, never file paths or WHATWG web streams.","triggerScenarios":"new Console({}) with no stdout; new Console({ stdout: {} }) where stdout has no write method; new Console({ stdout: '/tmp/app.log' }) passing a path string; passing a Deno.WritableStream / WritableStream (web stream) which exposes no write function.","commonSituations":"Building file loggers with node:console and assuming a path option exists; porting Deno-first code that passes web streams into Node APIs; forgetting destructuring defaults when options come from config objects.","solutions":["Pass a Node-style writable: new Console({ stdout: process.stdout }) or fs.createWriteStream(path)","For file logging: const out = fs.createWriteStream('./app.log', { flags: 'a' }); new Console({ stdout: out, stderr: out })","Adapt web streams with a thin wrapper: { write(chunk) { writer.write(chunk); } } forwarding to a WritableStreamDefaultWriter","Validate config before constructing: if (typeof opts.stdout?.write !== 'function') throw a descriptive configuration error"],"exampleFix":"// before\nconst { Console } = require('node:console');\nconst logger = new Console({ stdout: '/tmp/app.log' }); // ERR_CONSOLE_WRITABLE_STREAM\n\n// after\nconst fs = require('node:fs');\nconst out = fs.createWriteStream('/tmp/app.log', { flags: 'a' });\nconst logger = new Console({ stdout: out, stderr: out });","handlingStrategy":"validation","validationCode":"function makeConsole(opts) {\n  const { stdout, stderr } = opts ?? {};\n  if (typeof stdout?.write !== 'function') {\n    throw new TypeError('Console options.stdout must be a Node writable stream');\n  }\n  if (stderr !== undefined && typeof stderr?.write !== 'function') {\n    throw new TypeError('Console options.stderr must be a Node writable stream');\n  }\n  return new Console(opts);\n}","typeGuard":"const isNodeWritable = (v) => v != null && typeof v.write === 'function';","tryCatchPattern":"try {\n  logger = new Console(opts);\n} catch (e) {\n  if (e?.code === 'ERR_CONSOLE_WRITABLE_STREAM') logger = new Console({ stdout: process.stdout });\n  else throw e;\n}","preventionTips":["Never pass file paths or web streams to Console - wrap fs.createWriteStream instead","Validate logger config once at startup, not per log call","Convert WHATWG streams at the boundary with a small write() adapter"],"tags":["console","streams","logging","node-compat"],"backgroundTag":"console-writable-stream","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}