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
- Check whether the module uses a default export or named exports.
- 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'; // namedUnwrap interop defaults
- For a CommonJS module loaded from ESM, read .default if the namespace itself is not callable.
- 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
Node "Cannot read properties of undefined (reading X)" in CI - Fix the Null AccessFix the Node.js "Cannot read properties of undefined (reading X)" TypeError in CI by guarding the access or e…
Node "ReferenceError: X is not defined" in CI - Track Down the Missing SymbolFix the Node.js "ReferenceError: X is not defined" in CI by importing the symbol, defining the variable, or r…
Node CJS/ESM Default Import "is not a function" in CI - Fix the InteropFix a CommonJS-from-ESM default-import "is not a function" error in CI by reading the real callable off the i…