简体   繁体   中英

TypeError: Modele_1.default is not a constructor

I'm new to Webpack and typescrypt, so it may be a simple error, but I'm not capable to find it.

I import my model from the main.ts file :

 import View from "./View/View"; import Controller from "./Controller/Controller"; import Inventaire from "./Modele/Modele"; require("tether"); require("bootstrap"); function main(): void { let model = new Inventaire(); let controller = new Controller(model); let view = new View(controller); } main(); 

but when I run it I have an error in the console :

TypeError: Modele_1.default is not a constructor

model.ts :

 export default class Inventaire { private _achats: Achat[]; constructor(achats: Achat[] = [/*default values*/]) { this._achats = achats; }; /*...*/ } class Achat { Nom: string; private _Quantite: number; Prix: number; Description: string; Poids: number; Photo?: string[]; //path of the image constructor(nom: string, prix: number, description: string, poids: number = 0, photo?: string[]) { this.Nom = nom; this.Prix = prix; this.Description = description; this.Poids = poids; if (photo) this.Photo = photo; } } class ModelePanier { Contenu: Achat[]; Quantite: number = this.Contenu.length; PrixTotal(): number { let prix: number = 0; for (let achat of this.Contenu) { prix += achat.Prix; } return prix; } } 

I tried to use the import with and without default, but both don't work.

The following will definitely work:

export default class Inventaire {

And assuming the path ./Modele/Modele is correct the following will definitely work:

import Inventaire from "./Modele/Modele";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM