TypeScript - Solve the module has no exported member error
In this tutorial, we are going to learn about how to solve the module that has no exported member error in TypeScript.
When we try to import a member (ex: function, object etc) that doesn’t exist in the specified module, we will get the following error in our terminal.
Here is an example:
filename: maths.ts
export function add(a: number, b: number): number {
return a + b;
}
filename: index.ts
import {division} from "./maths";
Output:
Module '"./maths"' has no exported member 'divison'.ts(2305)
In the above code, we are importing the division
member in index.ts
file which is not an export member of maths.ts
file, so we will get the above error.
To solve this error, we need to makesure to import the member functions, objects etc which is available in the specified module with the correct names.
and also check if a member is a named export or default export.
Example of named export:
export function add(a: number, b: number): number {
return a + b;
}
export function multiply(a: number, b: number): number {
return a * b;
}
Example of default export:
export default checkEmpty;