gpt4 book ai didi

javascript - Angular:7.2.1 ES6 类 ReferenceError:初始化前无法访问 'X'

转载 作者:行者123 更新时间:2023-12-01 14:44:45 24 4
gpt4 key购买 nike

我有以下 TypeScript 类

export class Vehicule extends TrackableEntity {
vehiculeId: number;
constructor() {
super();
return super.proxify(this);
}
}

我在 tsconfig.json 中的 typescript 目标配置为 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 才能解决 this other problem .

编辑:
VehiculeGpsBoxInfo.ts 文件正在导入 Vehicule,如下所示:
import { Vehicule } from "./Vehicule";

编辑 2:我想说这可能与 webpack 相关,即模块在生成的模块中导出/导入的方式。

编辑3:经过进一步研究,这似乎与上面显示的代码无关。提出了一个关于 webpack and ES6 的新问题.

最佳答案

由于循环依赖,我收到了这个错误,比如

  • A 注入(inject) B
  • B 注入(inject) C
  • C 注入(inject) A

  • 删除循环依赖修复了这个错误。

    关于javascript - Angular:7.2.1 ES6 类 ReferenceError:初始化前无法访问 'X',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56870661/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com