Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: *.default is not a constructor

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

Here is the error:

Error: _mapAction2.default is not a constructor 

Here is the line of code that caused the error:

var mapAction = new MapAction(MapActionType.POLYGONDRAGGED, []); 

Here is the original typescript-file map-action.ts:

import { IMapAction} from './imap-action'; import { MapActionType } from './map-action-type.enum'; import {LatLngLiteral} from 'angular2-google-maps/core';  export class MapAction implements IMapAction{     type: MapActionType;     paths: Array<LatLngLiteral>;      constructor(mapActionType: MapActionType, paths: Array<LatLngLiteral>){         this.type = mapActionType;         this.paths = paths;     }      public getType(): MapActionType{         return this.type;     }      public getPaths(): Array<LatLngLiteral>     {         return this.paths;     }  } 

Here is the transpiled .js-file map-action.js:

"use strict"; class MapAction {     constructor(mapActionType, paths) {         this.type = mapActionType;         this.paths = paths;     }     getType() {         return this.type;     }     getPaths() {         return this.paths;     } } exports.MapAction = MapAction; //# sourceMappingURL=map-action.js.map 
like image 540
ChristopherMortensen Avatar asked Mar 07 '17 15:03

ChristopherMortensen


2 Answers

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'; 
like image 152
euvl Avatar answered Sep 24 '22 14:09

euvl


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

import LatLngLiteral from ''; 

to

import { LatLngLiteral } from ''; 
like image 22
Datsos Avatar answered Sep 23 '22 14:09

Datsos