如何修复TypeError:application_module__WEBPACK_IMPORTED_MODULE_1 ___ default.a不是构造函数

时间:2019-03-28 09:26:38

标签: javascript typescript webpack

我有构成类实例的代码,但发生错误

  

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只是实用程序类和接口的列表。

1 个答案:

答案 0 :(得分:0)

application-modulebuild/static/js/main-[hash].chunk.js中具有主package.json路径。要解决我的问题,我们需要将其更改为index.js,但是会发生新的错误:

Module parse failed: Unexpected token (10:25)
You may need an appropriate loader to handle this file type.
| import { enhancer } from './store/configureStore';
|
> export class Application implements IApp {

通过编辑webpack.config.js进行修复,将include: paths.appSrc中的include: paths.appPath更改为ts-loader

之后,webpack可以观看我的node_modules,但是又发生了另一个错误

Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

PS

所以,我处于终点。我的webpack配置无法在.ts目录之外编译src,因此我决定将.ts代码编译到esnext模块中。如果现在连接模块,所有操作将成功完成。