Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A module cannot have multiple default exports

I have only one export default line in my code. However, in WebStorm with Typescript, I get this TS Error:

Ts2528: a module cannot have multiple default exports

Here is the code:

ts import { ModelCreator } from 'entities/model-creator' export default ModelCreator() 
like image 636
MARCKON LIU Avatar asked Jul 13 '19 02:07

MARCKON LIU


People also ask

Can a module have more than one default export?

There are two different types of export, named and default. You can have multiple named exports per module but only one default export.

How many default exports can a module have?

Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export. Each type corresponds to one of the above syntax.

Why would you create a default export in a module?

Default Exports: Default exports are useful to export only a single object, function, variable. During the import, we can use any name to import.

How do I export multiple functions in react?

Use named exports to export multiple functions in React, e.g. export function A() {} and export function B() {} . The exported functions can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a single file.


2 Answers

Quick Way

As sometimes you can just reopen a file as stated in other answers, it doesn't always help, however.

Update: Dec 10, 2020. The previous option (see below) is not available in new versions of WebStorm. To restart the TS service now, you can use the following option:

New option

See more details on TypeScript tool window help center page.


Previous functionality (prior versions)

When you see lags like this one (and other weirdness from TS service), you can restart the TypeScript service by opening a TypeScript tool window and clicking on the "Restart" button (3rd button on the right side of the panel):

enter image description here

like image 127
Serhii Matrunchyk Avatar answered Sep 23 '22 23:09

Serhii Matrunchyk


I had the same error. After restarting WebStorm it worked again.

like image 41
Obiwahn Avatar answered Sep 23 '22 23:09

Obiwahn