简体   繁体   English

TypeError:Modele_1.default不是构造函数

[英]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. 我是Webpack和typescrypt的新手,所以它可能是一个简单的错误,但我找不到它。

I import my model from the main.ts file : 我从main.ts文件导入模型:

 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 : 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: 并假设路径./Modele/Modele是正确的,那么以下内容肯定会起作用:

import Inventaire from "./Modele/Modele";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:_reactQuery.default 不是构造函数 - TypeError: _reactQuery.default is not a constructor TypeError:Name.default不是构造函数 - TypeError: Name.default is not a constructor TypeError: bn_js_1.default 不是构造函数 - TypeError: bn_js_1.default is not a constructor 错误:未捕获 [TypeError:default is not a constructor] jest mock - Error: Uncaught [TypeError:default is not a constructor] jest mock 未捕获的类型错误:_konva.default.stage 不是构造函数 - Uncaught TypeError: _konva.default.stage is not a constructor TypeError:_user2.default不是构造函数JS - TypeError: _user2.default is not a constructor JS 获取未捕获的TypeError:...默认不是构造函数 - 来自Vue组件 - Getting Uncaught TypeError: …default is not a constructor - from Vue component “TypeError:chart_js__WEBPACK_IMPORTED_MODULE_9__.default 不是构造函数” - "TypeError: chart_js__WEBPACK_IMPORTED_MODULE_9__.default is not a constructor" VueJS 3 CLI 项目,TypeError 默认不是来自 ModalService 的构造函数 - VueJS 3 CLI project, TypeError default is not a constructor from ModalService WebpackError: TypeError: p5__WEBPACK_IMPORTED_MODULE_4___default.a 不是构造函数 - WebpackError: TypeError: p5__WEBPACK_IMPORTED_MODULE_4___default.a is not a constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM