Why am I getting 'cannot redefine property' error when updating application to angular 14

Viewed 93

I recently did an update to angular v14 and since then I got this error when I try to run my application:

Uncaught TypeError: Cannot redefine property: addHours
at Function.defineProperty ()
at 64434 (date.extensions.ts:7:8)
at webpack_require (bootstrap:19:1)
at 37562 (services.module.ts:17:41)
at webpack_require (bootstrap:19:1)
at 53907 (main.ts:13:37)

I tried to find what package makes this fail but I haven't found it yet.

My code:

declare interface Date {
  addHours(hours: number): Date;
  addMinutes(minutes: number): Date;
}

Object.defineProperty(Date.prototype, 'addHours', {
  configurable: true,
  enumerable: false,
  value: function(hours: number) {
    const date = new Date(this.valueOf());
    date.setHours(date.getHours() + hours);
    return date;
  }
});

Object.defineProperty(Date.prototype, 'addMinutes', {
  configurable: true,
  enumerable: false,
  value: function(minutes: number) {
    const date = new Date(this.valueOf());
    date.setMinutes(date.getMinutes() + minutes);
    return date;
  }
});

My packages:

"dependencies": {
  "@angular/animations": "14.0.2",
  "@angular/common": "14.0.2",
  "@angular/compiler": "14.0.2",
  "@angular/core": "14.0.2",
  "@angular/forms": "14.0.2",
  "@angular/localize": "14.0.2",
  "@angular/platform-browser": "14.0.2",
  "@angular/platform-browser-dynamic": "14.0.2",
  "@angular/router": "14.0.2",
  "@ngx-translate/core": "^14.0.0",
  "@ngx-translate/http-loader": "^7.0.0",
  "@nrwl/angular": "14.3.6",
  "core-js": "^3.23.1",
  "devextreme": "^21.2.8",
  "devextreme-angular": "^21.2.8",
  "devextreme-cldr-data": "^1.0.3",
  "globalize": "^1.7.0",
  "jasmine-marbles": "0.9.2",
  "moment": "^2.29.3",
  "ngx-moment": "^6.0.2",
  "rxjs": "^7.5.5",
  "tslib": "^2.4.0",
  "zone.js": "0.11.6"
},
"devDependencies": {
  "@angular-devkit/build-angular": "14.0.2",
  "@angular-eslint/eslint-plugin": "^13.5.0",
  "@angular-eslint/eslint-plugin-template": "^13.5.0",
  "@angular-eslint/template-parser": "^13.5.0",
  "@angular/cli": "~14.0.2",
  "@angular/compiler-cli": "14.0.2",
  "@angular/language-service": "14.0.2",
  "@nrwl/cypress": "14.3.6",
  "@nrwl/eslint-plugin-nx": "^14.3.6",
  "@nrwl/jest": "14.3.6",
  "@nrwl/linter": "^14.3.6",
  "@nrwl/workspace": "14.3.6",
  "@types/jasmine": "4.0.3",
  "@types/jasminewd2": "^2.0.10",
  "@types/jest": "28.1.1",
  "@types/jquery": "3.5.14",
  "@types/moment": "^2.13.0",
  "@types/node": "^18.0.0",
  "@typescript-eslint/eslint-plugin": "^5.24.0",
  "@typescript-eslint/parser": "^5.24.0",
  "cypress": "^6.2.1",
  "dotenv": "8.2.0",
  "eslint": "^8.18.0",
  "eslint-config-prettier": "^8.5.0",
  "eslint-plugin-import": "^2.26.0",
  "jasmine-core": "4.1.1",
  "jasmine-spec-reporter": "7.0.0",
  "jest": "27.5.1",
  "jest-preset-angular": "11.1.2",
  "nx": "14.3.6",
  "prettier": "2.7.1",
  "ts-node": "^10.8.1",
  "tslint": "6.1.3",
  "typescript": "4.6.4"
}
0 Answers
Related