【发布时间】:2019-03-29 16:17:35
【问题描述】:
我有创建类实例的代码,但发生错误
TypeError: application_module__WEBPACK_IMPORTED_MODULE_1___default.a 不是构造函数
index.ts
import Application from 'application-module';
const app = new Application();
应用程序模块
import { IApp, ModuleRoute, IReducerContainer } from 'common-module';
export default class Application implements IApp {
routes: ModuleRoute[];
reducers: IReducerContainer[];
constructor() {
this.routes = [];
this.reducers = [];
}
addRoute(path: any, component: any) {
this.routes.push({ path, component });
}
}
common-module 只是一个实用类和接口的列表。
【问题讨论】:
-
尝试在应用程序模块中删除
default并将导入更改为import { Application } from 'application-module'; -
@PrzemyslawPietrzak 谢谢你,我试着用这种方式重写它,但得到了同样的错误
-
没有
default你得到TypeError: application_module__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructo? -
@PrzemyslawPietrzak 没有默认我得到
TypeError: application_module__WEBPACK_IMPORTED_MODULE_1__.Application is not a constructor -
其他:当你从源文件导入文件时,你应该使用相对路径:例如
import Application from './application-module';请尝试以这种方式导入应用程序
标签: javascript typescript webpack