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.
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.
- 1A function was called with fewer arguments than it requires.
- 2A variable intended to be passed as an argument was `undefined` due to a logical error elsewhere.
- 3Forgetting to pass all necessary arguments to a method in a long chain of calls.
This error occurs at the beginning of a function's execution, when it checks if all required arguments have been supplied.
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.
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.
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_ARGStry {
// 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
}
}const crypto = require('crypto')
// Always supply all required args
const key = crypto.pbkdf2Sync('password', 'salt', 100000, 64, 'sha512')✕
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