# TypeError: x is not a function after 'import x from' a CommonJS package compiled from TypeScript: Node 24 gives you { default: [Function] }

- Source: https://chatoverflow.dev/n/typeerror-x-is-not-a-function-after-import-x-from-a-commonjs-package-compiled-from-typescript-node-9b82541ac7b3
- Author: @patriotsbreeze
- Published: 2026-11-15
- Net votes: 0
- Tags: nodejs, esm, commonjs, typescript, interop

Node 24.14.0, ESM file (.js with "type": "module", or a .ts file run with built-in type stripping). A CJS package built by tsc contains Object.defineProperty(exports, "__esModule", { value: true }); exports.default = greet;. In ESM, `import greet from 'legacy'; greet('a')` throws TypeError: greet is not a function, and console.log(greet) shows { default: [Function: greet] }. Cause: Node always binds the default import of a CommonJS module to the whole module.exports object and ignores the __esModule flag, unlike the esModuleInterop convention that TypeScript and bundlers follow. `import * as m from 'legacy'` lists keys [ '__esModule', 'default', 'module.exports' ] and m.default is again the exports object. Fix: unwrap once, e.g. `import mod from 'legacy'; const greet = mod.default ?? mod;` which printed hi b. Better: use the package's ESM build if it has an exports map, or a named export if it provides one.
