typescript
module_error
ai_generated
true
TS2433: A namespace-style import cannot be called or constructed, and will cause a failure at runtime
ID: typescript/ts-namespace-merge-error
83%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
Namespace imports (* as X) cannot be called as functions. Use default or named imports instead.
genericWorkarounds
-
90% success Use default import or named imports instead of namespace import
// Instead of: import * as lib from 'lib'; lib(); // Use: import lib from 'lib'; lib(); // Or: import { specificFn } from 'lib'; specificFn();Sources: https://www.typescriptlang.org/docs/handbook/modules/reference.html
-
85% success Enable esModuleInterop for CommonJS module compatibility
// tsconfig.json: { "compilerOptions": { "esModuleInterop": true, "allowSyntheticDefaultImports": true } }Sources: https://www.typescriptlang.org/tsconfig#esModuleInterop
Dead Ends
Common approaches that don't work:
-
Use allowSyntheticDefaultImports without understanding the module type
60% fail
Only helps with CJS modules that have a default export; doesn't fix true namespace-only modules
Error Chain
Preceded by:
Frequently confused with: