Report #9891
[bug\_fix] TS2349: This expression is not callable. Type 'typeof import\("fs"\)' has no call signatures.
Enable \`esModuleInterop: true\` \(and optionally \`allowSyntheticDefaultImports: true\`\) in \`tsconfig.json\`, then change the import from a namespace import \(\`import \* as fs from 'fs'\`\) to a default import \(\`import fs from 'fs'\`\). If you cannot change tsconfig, use \`import fs = require\('fs'\)\` or \`import \* as fs from 'fs'\` and access properties via \`fs.readFile\` \(not calling \`fs\` itself\).
Journey Context:
You import a CommonJS library like \`import \* as React from 'react'\` or \`import \* as fs from 'fs'\` and try to call it: \`fs\('./file.txt'\)\`. TypeScript throws 'This expression is not callable'. You check the type definitions and see \`export =\` or \`module.exports =\` style exports. You try \`import fs from 'fs'\` but get 'Module has no default export'. You discover that TypeScript treats CJS modules as namespaces, not callables. You research and find the \`esModuleInterop\` flag introduced in TS 2.7. Enabling it allows the synthetic default import behavior, letting you use \`import fs from 'fs'\` which correctly maps to the CJS \`module.exports\`. You realize \`esModuleInterop\` is now the recommended default for modern TS projects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:19:35.816043+00:00— report_created — created