ERR_MISSING_ARGS
Node.jsERRORNotableAPI UsageHIGH confidence

A required function argument was not provided.

Production Risk

Medium. This indicates a clear programming error but is often caught during development. If it reaches production, it points to a lack of testing for a specific code path.

What this means

This error is thrown when a required function or method is called without one or more of its mandatory arguments. Node.js APIs often have several required parameters to function correctly. Leaving one out violates the API's contract and prevents it from executing.

Why it happens
  1. 1A function was called with fewer arguments than it requires.
  2. 2A variable intended to be passed as an argument was `undefined` due to a logical error elsewhere.
  3. 3Forgetting to pass all necessary arguments to a method in a long chain of calls.
How to reproduce

This error occurs at the beginning of a function's execution, when it checks if all required arguments have been supplied.

trigger — this will error
trigger — this will error
const crypto = require('crypto');
// The 'pbkdf2Sync' function requires at least 5 arguments.
try {
  crypto.pbkdf2Sync('password', 'salt');
} catch (err) {
  console.error(err);
}

expected output

TypeError [ERR_MISSING_ARGS]: The 'iterations', 'keylen', and 'digest' arguments are required.

Fix

Provide All Required Arguments

WHEN Calling a function or method.

Provide All Required Arguments
const crypto = require('crypto');
// Provide all required arguments: password, salt, iterations, keylen, and digest.
const key = crypto.pbkdf2Sync('password', 'salt', 100000, 64, 'sha512');
console.log(key.toString('hex'));

Why this works

Consult the official Node.js documentation for the function you are calling to understand its signature and which arguments are required versus optional.

Code examples
Triggerjs
const crypto = require('crypto');
// The 'pbkdf2Sync' function requires at least 5 arguments.
try {
  crypto.pbkdf2Sync('password', 'salt');
} catch (err) {
  console.error(err);  // this triggers ERR_MISSING_ARGS
Handle in try/catchjs
try {
  // operation that may throw ERR_MISSING_ARGS
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_MISSING_ARGS') {
    console.error('ERR_MISSING_ARGS:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
const crypto = require('crypto')
// Always supply all required args
const key = crypto.pbkdf2Sync('password', 'salt', 100000, 64, 'sha512')
What not to do

Sources
Official documentation ↗

https://github.com/nodejs/node/blob/main/lib/internal/errors.js

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors