1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Angular: 7.2.1 ES6 class ReferenceError : Cannot access 'X' before initialization

Discussão em 'Angular' iniciado por anon, Outubro 9, 2024 às 22:52.

  1. anon

    anon Guest

    I'm having the following TypeScript class

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


    my typescript target in tsconfig.json is configured as es6:

    "compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    }


    At runtime, here in Chrome, the code is failing with:

    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)


    I needed to change es5 to es6 to solve this other problem.


    EDIT: The VehiculeGpsBoxInfo.ts file is importing Vehicule like this:

    import { Vehicule } from "./Vehicule";


    EDIT 2: I vould say that this may be webpack related, the way that modules are exported/imported in the genrated modules.

    EDIT 3: After further research, this seems to have nothing to do with the code shown above. Started a new question about webpack and ES6.

    Continue reading...

Compartilhe esta Página