How to fix Module has no exported member 'default' in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025ยท 207 views

This TypeScript error occurs when trying to import a default export from a module that doesn't have one. The module might use named exports instead, or the export configuration may be incorrect. Fixes include using named imports, checking module's export structure, or configuring esModuleInterop.

Quick fix

Fixes TS2305

// If module has named exports like this:
export function calculate() { /* ... */ }
export const PI = 3.14;
export class Calculator { /* ... */ }

// You CANNOT import it like this:
import MyModule from "./calculator";  // ERROR: No default export

// Instead use named imports:
import { calculate, PI, Calculator } from "./calculator";
  1. Check the module's actual exports
  2. Use named imports for modules without default export
  3. Configure esModuleInterop in tsconfig.json
  4. Check package.json for module type
typescript โ€” error
// If module has named exports like this:
export function calculate() { /* ... */ }
export const PI = 3.14;
export class Calculator { /* ... */ }
// You CANNOT import it like this:
import MyModule from "./calculator"; // ERROR: No default export
// Instead use named imports:
import { calculate, PI, Calculator } from "./calculator";
Module has no exported member 'default'

What this error means

The "Module has no exported member 'default'" error (TS2305) happens when TypeScript cannot find a default export in the module you're importing from. This typically occurs when: 1. **Module uses named exports only**: The module exports individual functions/classes using `export function` or `export class` but doesn't have a `export default`. 2. **Incorrect import syntax**: Using `import X from "module"` when the module only has named exports like `export { something }`. 3. **CommonJS module with module.exports**: Some CommonJS modules use `module.exports = something` which TypeScript may interpret differently based on `esModuleInterop` settings. 4. **Mixed module systems**: Confusion between ES modules (import/export) and CommonJS (require/module.exports). TypeScript needs to match the import syntax with the actual export structure of the module. When you use `import X from "module"`, TypeScript looks for a `export default X` or equivalent in the target module. If it doesn't find one, you get this error.

Typical symptoms

  • Compilation fails with 'Module has no exported member 'default''
  • IDE shows red underlines on import statements using 'import X from' syntax
  • Error code TS2305 appears in compiler output
  • Import works in JavaScript but fails in TypeScript
  • Recently changed from named imports to default import
  • Switching between different module formats (ESM vs CommonJS)

Common causes

  1. Module only has named exports but you're trying to import it as default
  2. Using 'import X from' syntax for a module that exports multiple named members
  3. CommonJS module using 'module.exports =' without proper TypeScript configuration
  4. Missing or incorrect 'esModuleInterop' setting in tsconfig.json
  5. Package's type definitions incorrectly specify export structure
  6. Trying to import a module that doesn't export anything
  7. Module uses 'export =' syntax (TypeScript-specific) instead of 'export default'
  8. Mixed use of ES modules and CommonJS in the same project

How to fix "Module has no exported member 'default'"

1Check the module's actual exports

First, examine what the module actually exports. Look at its source or type definitions:

typescript
// If module has named exports like this:
export function calculate() { /* ... */ }
export const PI = 3.14;
export class Calculator { /* ... */ }

// You CANNOT import it like this:
import MyModule from "./calculator";  // ERROR: No default export

// Instead use named imports:
import { calculate, PI, Calculator } from "./calculator";

Check the module's documentation or type definitions (.d.ts files) to see its export structure. In VS Code, you can hover over the import to see available exports.

2Use named imports for modules without default export

If the module only has named exports, import the specific members you need:

typescript
// Module: math-utils.ts
export function add(a: number, b: number) { return a + b; }
export function multiply(a: number, b: number) { return a * b; }

// WRONG - trying to import default
import mathUtils from "./math-utils";  // ERROR

// CORRECT - import named exports
import { add, multiply } from "./math-utils";

// CORRECT - import everything as namespace
import * as mathUtils from "./math-utils";
mathUtils.add(1, 2);

For third-party packages, check their documentation for correct import syntax.

3Configure esModuleInterop in tsconfig.json

For CommonJS modules that use module.exports = something, enable esModuleInterop:

json
{
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

These settings allow TypeScript to treat CommonJS modules as if they have default exports:

typescript
// With esModuleInterop: true
import express from "express";  // Works even though express uses module.exports
// Compiled to: const express = require("express").default || require("express")

// Without esModuleInterop: true
import * as express from "express";  // Must use namespace import
// or
import express = require("express");  // TypeScript-specific syntax

After changing tsconfig.json, restart your TypeScript server.

4Check package.json for module type

Verify if the package uses ES modules or CommonJS:

json
// package.json indicating ES modules
{
  "type": "module",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  }
}

// package.json indicating CommonJS (default)
{
  "main": "./dist/index.js"
}

For ES module packages ("type": "module"), ensure your tsconfig.json uses appropriate settings:

json
{
  "compilerOptions": {
    "module": "node16",
    "moduleResolution": "node16"
  }
}

For mixed packages, you might need to use dynamic imports or different import syntax.

5Fix imports for CommonJS modules

For CommonJS modules without default exports, use one of these patterns:

typescript
// Pattern 1: Namespace import (works with esModuleInterop: false)
import * as fs from "fs";
fs.readFileSync("./file.txt");

// Pattern 2: Require syntax (TypeScript-specific)
import fs = require("fs");

// Pattern 3: Destructured require (for specific exports)
const { readFileSync } = require("fs");

// Pattern 4: With esModuleInterop: true, you can often use default import
import fs from "fs";  // Only works with esModuleInterop: true

// For modules that export a single function/class:
// If module has: module.exports = MyClass
import MyClass from "./MyClass";  // With esModuleInterop: true

Check the module's actual export structure to choose the right pattern.

6Create or fix type definitions for JavaScript modules

If you're using a JavaScript module without proper types, create a declaration file:

typescript
// types/my-module.d.ts
declare module "my-module" {
  // If module has default export
  export default function myFunction(): void;

  // If module has named exports
  export function helper(): string;
  export const version: string;

  // If module uses CommonJS export
  export = myFunction;
  // or for object exports
  namespace myModule {
    export function doSomething(): void;
  }
  export = myModule;
}

Ensure the declaration matches the actual module structure. Test by checking what require("my-module") returns in Node.js.

Advanced notes

### Understanding Module Export Patterns

TypeScript supports several export patterns:

1. ES Module Default Export:

typescript
// Export
export default function myFunction() { /* ... */ }
// or
export default class MyClass { /* ... */ }

// Import
import myFunction from "./module";

2. ES Module Named Exports:

typescript
// Export
export function func1() { /* ... */ }
export const CONSTANT = "value";

// Import
import { func1, CONSTANT } from "./module";

3. CommonJS module.exports:

javascript
// Export
module.exports = myFunction;
// or
module.exports = { func1, func2 };

// Import (with esModuleInterop: true)
import myFunction from "./module";
// or
import * as module from "./module";

4. TypeScript export = (for CommonJS compatibility):

typescript
// Export
function myFunction() { /* ... */ }
export = myFunction;

// Import (TypeScript-specific)
import myFunction = require("./module");

### esModuleInterop and allowSyntheticDefaultImports

- esModuleInterop: Changes runtime behavior to allow default imports from CommonJS modules. Adds helper code to check for .default property.

- allowSyntheticDefaultImports: Only affects type checking, not runtime. Allows you to write import React from "react" even if types say there's no default export.

For modern projects, set both to true in tsconfig.json.

### Module Resolution with Node16/NodeNext

With "moduleResolution": "node16" or "nodeNext":

typescript
// Must include .js extension for relative imports
import { helper } from "./utils/helper.js";  // Even if source is helper.ts

// For package imports, extension is not needed
import lodash from "lodash";

This matches Node.js's actual ES module resolution.

### Checking Module's Exports

Use these techniques to inspect a module:

bash
# Check JavaScript module's exports
node -e "console.log(Object.keys(require('module-name')))"

# For ES modules, check package.json exports field
cat node_modules/module-name/package.json | grep -A 10 '"exports"'

# Use TypeScript compiler to see resolved types
npx tsc --noEmit --traceResolution

### Dynamic Imports as Alternative

When unsure about export structure, use dynamic imports:

typescript
// Runtime check of available exports
import("module-name").then(module => {
  if (module.default) {
    // Has default export
    const func = module.default;
  } else {
    // Only named exports
    const { namedExport } = module;
  }
});

This avoids compile-time errors but adds runtime complexity.

Frequently asked questions

What does "TS2305" mean?
The "Module has no exported member 'default'" error (TS2305) happens when TypeScript cannot find a default export in the module you're importing from. This typically occurs when: 1. Module uses named exports only: The module exports individual functions/classes using export function or export class but doesn't have a export default.
How do I fix "TS2305"?
This TypeScript error occurs when trying to import a default export from a module that doesn't have one. The module might use named exports instead, or the export configuration may be incorrect. Fixes include using named imports, checking module's export structure, or configuring esModuleInterop.
What causes "TS2305"?
Module only has named exports but you're trying to import it as default Using 'import X from' syntax for a module that exports multiple named members CommonJS module using 'module.exports =' without proper TypeScript configuration
Is the "TS2305" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading