Module has no exported member error in TypeScript

avatar

Borislav Hadzhiev

Last updated: Jul 25, 2022

banner

Photo from Unsplash

Module has no exported member error in TypeScript #

The error "Module has no exported member" occurs when we try to import a member that doesn't exist in the specified module. To solve the error, make sure the module exports the specific member and you haven't mistyped the name or mistaken named for default import.

module has no exported member

Here is an example of how the error occurs. This is a file called another-file.ts

another-file.ts
export function sum(a: number, b: number) { return a + b; }

And this is a file called index.ts

index.ts
// ⛔️ Error: Module '"./another-file"' has no // exported member 'multiply'.ts(2305) import { multiply } from './another-file'; console.log(multiply(15, 15));

Notice that another-file.ts does not export a function named multiply, so when we try to import a non-existent member from the module, we get the error.

If you are importing from a third-party library, make sure that it exports the specific member and that you haven't mistyped the name.

If the member was exported using a named export, you have to wrap the import in curly braces.

another-file.ts
// 👇️ named export export function sum(a: number, b: number) { return a + b; } const num = 350; // 👇️ default export export default num;

And you would import a default and a named exports as:

index.ts
// 👇️ default and named imports import num, { sum } from './another-file'; console.log(sum(num, num)); // 👉️ 700

Notice that we don't wrap the default export in curly braces when importing it.

If you are getting the error when importing from local files, make sure the specified path to the module is correct.

For example, if you are importing from one directory up, you would do import {myFunction} from '../myFile'.

You might have tried to import the specific member from a different file (one that doesn't export it).

In my experience, it's best to use your IDE for autocompletion to avoid getting the "Module has no exported member" error.

If you write the path to a module first and place curly braces, in VSCode (and in most other editors), you can press ctrl + space and get autocompletion for the module's named exports.

index.ts
import { CTRL + Space here } from './another-file';

You can also leverage your IDE to autocomplete the path if you are importing from a local file.

Conclusion #

The error "Module has no exported member" occurs when we try to import a member that doesn't exist in the specified module. To solve the error, make sure the module exports the specific member and you haven't mistyped the name or mistaken named for default import.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.