Lingua-e
JavaScript

What is a ERR_INVALID_ARG_TYPE?

← Errors

Node.js throws ERR_INVALID_ARG_TYPE when a built-in API function receives an argument of the wrong type. The error message specifies the argument name, the expected type(s), and the actual value received.

Why it happens

  • Passing a number where a file path string is expected.
  • Passing undefined or null to a function that requires a Buffer or string.
  • A variable holding the wrong type due to an earlier logic error.
  • Destructuring the wrong property from an object before passing it to an API.

Examples

JavaScript

Code that triggers the error

const fs = require("fs");
fs.readFile(123, "utf8", (err, data) => console.log(data));

Error output

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type number (123)

How to fix it

Read the error message carefully: it names the argument and the expected type. Validate input types before passing them to Node.js APIs. Use TypeScript or JSDoc types to catch these mismatches at development time.

Fixed code

const fs = require("fs");
fs.readFile("./data.txt", "utf8", (err, data) => {
  if (err) throw err;
  console.log(data);
});

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free