Error: *.default is not a constructor

后端 未结 4 833
栀梦
栀梦 2020-12-15 15:04

I get the following error, when testing some javascript code, transpiled from a typescript file.

Here is the error:

Error: _mapAction2.default is not         


        
相关标签:
4条回答
  • 2020-12-15 15:28

    Since classes in javascript are syntactic sugar, I figured I'd try to solve this issue without them. For me, switching the architecture over to prototypes seems to have solved my issue. Posting in case anyone else runs into this issue but is already doing export default

    0 讨论(0)
  • 2020-12-15 15:29

    Check that your import is correct. you might miss {} for example.

    import LatLngLiteral from '';
    

    to

    import { LatLngLiteral } from '';
    
    0 讨论(0)
  • 2020-12-15 15:38

    Another solution would be to add "esModuleInterop": true, into tsconfig.json.

    esModuleInterop allows default imports from modules with no default export.

    0 讨论(0)
  • 2020-12-15 15:44

    You need to export a default value which will look like:

    export default class MapAction implements IMapAction {...
    

    And import it as:

    import MapAction from './map_action_file';
    

    Alternatively, if you want to export multiple things from the module you can do something like:

    export class MapAction ...
    export class MapSomethng ...
    

    And import it as follows:

    import { MapAction, MapSomething } from './map_action_file';
    
    0 讨论(0)
提交回复
热议问题