TypeScript says a module has no exported member
Module './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.
Fix it fast
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'"2Match what you see, then jump to its fix
- 1
The error names a file in your own source folderThe member is a default export, or not exportedFix - 2
The 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
The editor shows the error but npx tsc --noEmit passesVS Code uses a different TypeScript version than your projectFix
- 1
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.tsx2Fix
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 --noEmitConfirmed by typescriptlang.org
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 --noEmitConfirmed by typescriptlang.org
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 --version2Fix
Run the command TypeScript: Select TypeScript Version and choose the workspace version.
// Command Palette
TypeScript: Select TypeScript Version3Verify
The editor error matches what the compiler says.
npx tsc --noEmitConfirmed by code.visualstudio.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
TypeScript refuses JSX because the jsx option is not set
TS17004: Cannot use JSX unless the '--jsx' flag is provided.
TypeScript compiles JSX only when you name the file with a .tsx extension and enable the jsx compiler option.
2 causes, each with a fixWeb apps
TypeScript rejects a component that returns an array or other non-Element
Its return type 'Element[]' is not a valid JSX element.
TypeScript before 5.1 required every component to return JSX.Element or null, so arrays, strings and Promises were rejected even though React renders them.
2 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint reports no-unused-vars for React components and imports that are used
no-unused-vars reported for a component that is rendered as a JSX tag
ESLint's core no-unused-vars does not see variables used only as JSX tags, so a component imported and rendered as <Hello /> looks unused.
3 causes, each with a fixWeb 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 fixWeb apps
The renderInput prop stopped working on the MUI X DatePicker
The custom TextField (variant, size, helperText) is ignored
renderInput was removed from the MUI X date pickers in version 6.
3 causes, each with a fix