我有以下 TypeScript 课程
export class Vehicule extends TrackableEntity {
vehiculeId: number;
constructor() {
super();
return super.proxify(this);
}
}
我在 tsconfig.json 中的打字稿目标配置为 es6:
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
}
在运行时,在 Chrome 中,代码失败并显示:
ReferenceError: Cannot access 'Vehicule' before initialization
at Module.Vehicule (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:10559:100)
at Module../src/app/domain/models/VehiculeGpsBoxInfo.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:11156:69)
at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
at Module../src/app/domain/models/Vehicule.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:10571:78)
at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
at Module../src/app/components/dispositifsDATI/mainDATI/listDATI/listDATI.component.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:6447:82)
at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
at Module../src/app/components/dispositifsDATI/index.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:3053:95)
at __webpack_require__ (https://localhost:44338/runtime.js:84:30)
at Module../src/app/components/dispositifsDATI/dispositifsDATI.routes.ts (https://localhost:44338/src-app-components-dispositifsDATI-dispositifsDATI-module.js:2982:64)
我需要将 es5 更改为 es6 来解决这另一个问题 https://stackoverflow.com/questions/51860043/javascript-es6-typeerror-class-constructor-client-cannot-be-invoked-without-ne.
编辑:
VehiculeGpsBoxInfo.ts 文件正在导入 Vehicule,如下所示:
import { Vehicule } from "./Vehicule";
编辑 2:我想说这可能与 webpack 相关,即在生成的模块中导出/导入模块的方式。
编辑3:经过进一步研究,这似乎与上面显示的代码无关。开始了一个新问题webpack 和 ES6 https://stackoverflow.com/questions/56884546/do-i-need-to-configure-webpack-for-es6.