- Error
- Reported by the type checker
TS1192
Module '{0}' has no default export.
A default import names a module that has no default export. Import a named export instead, or add a default export.
What it means
import x from "./mod" reads the module's default export. If the module only has named exports, there's nothing to import. With esModuleInterop or allowSyntheticDefaultImports some CommonJS modules can be default-imported, but ES modules without a default export never can.
Example
import config from './config';
export { config };
export const port = 8080;
{
"compilerOptions": {
"strict": true,
"target": "es2022",
"module": "esnext",
"moduleResolution": "bundler",
"noEmit": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": false
}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(1,8): error TS1192: Module '"./config"' has no default export.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01.
How to fix
- Import the named export:
import { port } from "./config";. - Or import the whole module as a namespace:
import * as config from "./config";. - If you own the module, add
export default ...to it.