admin管理员组

文章数量:1122832

I'm currently working on an Angular 18 project and using the @automapper/core package version 8.8.1. The decorators provided by @automapper/core work perfectly when running the project with ng serve. However, after building the project with ng build --configuration=production, the decorators stop working. An example of this, the mapping between jwt-token.dto.ts and jwt-token.model.ts results in an object with all properties set to undefined. Here are samples of the DTO and model files:

// JWTToken.dto.ts
/* eslint-disable camelcase */
import { AutoMap } from "@automapper/classes";

export class JWTTokenDto {
    @AutoMap()
    public token!: string;

    @AutoMap()
    public refresh_token?: string;
}
// JWTToken.model.ts
import { Entity } from "src/app/common/entity/base/entity.model";
import { AutoMap } from "@automapper/classes";

export class JWTToken extends Entity {
    @AutoMap()
    public token!: string;

    @AutoMap()
    public refreshToken?: string;
}

Output object has all properties declared to undefined.

Additional context: My tsconfig.json is configured as follows:

{
  "compilerOptions": {
    "target": "es2022",
    "module": "commonjs",
    "lib": ["es2022", "dom"],
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "outDir": "./dist/out-tsc",
    "moduleResolution": "node",
    "types": [],
    "typeRoots": ["node_modules/@types"],
    "esModuleInterop": true,
    "skipLibCheck": true,
    "strict": true,
    "baseUrl": "./",
    "paths": {
      "@app/*": ["src/app/*"],
    }
  },
  "exclude": ["node_modules", "dist"],
  "angularCompilerOptions": {
    "strictTemplates": true,
    "strictInjectionParameters": true
  }
}

My project dependency looks like this:

{
  "dependencies": {
    "@angular/animations": "^18.2.0",
    "@angular/common": "^18.2.0",
    "@angular/compiler": "^18.2.0",
    "@angular/core": "^18.2.0",
    "@angular/forms": "^18.2.0",
    "@angular/platform-browser": "^18.2.0",
    "@angular/platform-browser-dynamic": "^18.2.0",
    "@angular/router": "^18.2.0",
    "@automapper/classes": "^8.8.1",
    "@automapper/core": "^8.8.1",
    "reflect-metadata": "^0.1.14",
    "rxjs": "~7.8.0",
    "zone.js": "~0.14.10"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^18.2.6",
    "@angular/cli": "^18.2.6",
    "@angular/compiler-cli": "^18.2.0",
    "typescript": "~5.5.2",
    "jest": "^29.0.3"
  }
}

Has anyone encountered a similar issue or could provide guidance on how to ensure that the decorators work properly in the production build? Thank you!

I tried changing the "moduleResolution". At the beginning was set to "bundle" I tried to tweak the tsconfig.json but to no avail

本文标签: typescriptautomappercore Decorators Not Working After Production Build in Angular 18Stack Overflow