Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript says a module has no exported member

ErrorModule './Button' has no exported member 'Button'. ts(2305)

Short answer

TS2305 means the file you import from does not export that name, as far as TypeScript can see. Open the module and check the exact export: it may be a default export, a different name, or not exported at all. For a package, the types TypeScript loads depend on moduleResolution and the package's exports field.

  • Applies to TypeScript 5.x, VS Code, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Let the compiler show what it resolved. This prints the file TypeScript opened for the import, so you read the real exports instead of guessing.

    npx tsc --noEmit --traceResolution | grep -n "'./Button'"
  2. 2Match what you see, then jump to its fix

    1. 1The error names a file in your own source folderThe member is a default export, or not exportedFix
    2. 2The error names a package from node_modules, and the member exists in its documentationA package's types are found through a different path than you expectFix
    3. 3The editor shows the error but npx tsc --noEmit passesVS Code uses a different TypeScript version than your projectFix

What does the error look like?

  • Module './Button' has no exported member 'Button'. ts(2305)
  • Module '"pkg"' has no exported member 'name'. ts(2305)

Cause 1 of 3

The member is a default export, or not exported

1Check

A file can have one default export plus any number of named exports. A named import only works for something marked export with that exact name.

grep -n "export" src/Button.tsx

2Fix

Match the import to the export. Default export gets no braces; named exports get braces and the exact name.

// Button.tsx has: export default function Button() {}
import Button from './Button';

// Button.tsx has: export function Button() {}
import { Button } from './Button';

3Verify

Run the type check; the error is gone.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 3

A package's types are found through a different path than you expect

1Check

TypeScript reads a package's exports field only when moduleResolution is node16, nodenext or bundler. With node10 it uses types, typings and main instead, and the two paths can lead to different declaration files.

grep -n "moduleResolution" tsconfig*.json
npx tsc --noEmit --traceResolution | grep -n "pkg"

2Fix

For an app built with Vite, webpack or esbuild, set moduleResolution to bundler so TypeScript resolves packages the way the bundler does.

{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "bundler"
  }
}

3Verify

Run the type check again.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 3 of 3

VS Code uses a different TypeScript version than your project

1Check

VS Code uses its bundled TypeScript unless you pick the workspace version.

npx tsc --version

2Fix

Run the command TypeScript: Select TypeScript Version and choose the workspace version.

// Command Palette
TypeScript: Select TypeScript Version

3Verify

The editor error matches what the compiler says.

npx tsc --noEmit

Confirmed by code.visualstudio.com

Did this fix it?

How do I stop it coming back?

  • Prefer named exports in app code so a wrong import name fails the same way everywhere.
  • Run tsc --noEmit in CI so the editor is not the only place errors show up.
  • Pin the TypeScript version in package.json and select it in VS Code.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.