Skip to content
Latchkey

Node "TypeError: X is not a function" in CI - Fix the Bad Call

This TypeError means you called something that is not callable. The value exists but is undefined, an object, or the wrong member of a module.

What this error means

A node process throws TypeError: <name> is not a function at a call site, often right after importing a module whose export shape differs from what the code expects.

node
/home/runner/work/app/app/src/index.js:5
fetchData();
^

TypeError: fetchData is not a function
    at Object.<anonymous> (/home/runner/work/app/app/src/index.js:5:1)

Common causes

Default vs named export confusion

A module exports a function as default but the code destructures it as a named export (or vice versa), so the value is undefined.

A CommonJS/ESM interop quirk

An interop default wrapper means the real function lives under .default, and calling the namespace object directly fails.

How to fix it

Match the export shape

  1. Check whether the module uses a default export or named exports.
  2. Import it the matching way so the value you call is actually a function.
JavaScript
import fetchData from './fetchData.js'; // default
// or
import { fetchData } from './fetchData.js'; // named

Unwrap interop defaults

  1. For a CommonJS module loaded from ESM, read .default if the namespace itself is not callable.
  2. Confirm the resolved value is a function before calling it.
JavaScript
import mod from 'legacy-cjs';
const fn = mod.default ?? mod;

How to prevent it

  • Enable TypeScript or import linting so export-shape mismatches are caught at build time rather than surfacing as runtime TypeErrors in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →