在使用 Angular & Kendo UI 的 AOT 构建中出现错误“标识符 'territoryFromName' 已被声明”

Error ''Identifier 'territoryFromName' has already been declared" on AOT build with Angular & Kendo UI

最近,在我们的软件包没有任何版本更改的情况下,我们的 AOT 构建失败并显示此错误消息:

ERROR in chunk vendor [initial] [name].bundle.js Identifier
'territoryFromName' has already been declared (13:9)
}

function territoryFromName(name, identity) { var likelySubtags = __WEBPACK_MODULE_REFERENCE__7_636c6472__.supplemental.likelySubtags; var parts = name.split("-");

我们的 package.json 文件如下所示:

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "build": "webpack --config webpack.config.js",
    "build:Production": "npm run fixmem && webpack --config webpack.config.prod.js --env.Production",
    "build:test": "webpack --config webpack.config.testAOT.js",
    "fixmem": "node increase-webpack-memory.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "5.2.5",
    "@angular/common": "5.2.5",
    "@angular/compiler": "5.2.5",
    "@angular/core": "5.2.5",
    "@angular/forms": "5.2.5",
    "@angular/http": "5.2.5",
    "@angular/platform-browser": "5.2.5",
    "@angular/platform-browser-dynamic": "5.2.5",
    "@angular/platform-server": "5.2.5",
    "@angular/router": "5.2.5",
    "@progress/kendo-angular-buttons": "4.1.2",
    "@progress/kendo-angular-dateinputs": "3.4.4",
    "@progress/kendo-angular-dialog": "3.6.2",
    "@progress/kendo-angular-dropdowns": "3.0.2",
    "@progress/kendo-angular-excel-export": "2.1.1",
    "@progress/kendo-angular-grid": "3.5.1",
    "@progress/kendo-angular-inputs": "3.2.0",
    "@progress/kendo-angular-intl": "1.4.1",
    "@progress/kendo-angular-l10n": "1.2.0",
    "@progress/kendo-angular-layout": "3.1.1",
    "@progress/kendo-angular-popup": "2.4.1",
    "@progress/kendo-angular-tooltip": "0.4",
    "@progress/kendo-angular-upload": "4.1.4",
    "@progress/kendo-data-query": "1.4.0",
    "@progress/kendo-drawing": "1.5.6",
    "@progress/kendo-ui": "2018.2.704",
    "@progress/telerik-angular-report-viewer": "3.18.125",
    "@telerik/kendo-intl": "1.3.2",
    "angular-tree-component": "7.1.0",
    "babel-polyfill": "6.9.1",
    "bootstrap": "4.0.0",
    "es6-shim": "0.35.3",
    "jquery": "3.2.1",
    "moment": "2.18.1",
    "moment-timezone": "0.5.13",
    "oidc-client": "1.4.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.6",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@angular-devkit/core": "0.3.2",
    "@angular/cli": "1.7.4",
    "@angular/compiler-cli": "5.2.5",
    "@angular/language-service": "5.2.0",
    "@ngtools/webpack": "1.10.2",
    "@progress/kendo-theme-default": "2.54.0",
    "@types/jasmine": "2.8.3",
    "@types/jasminewd2": "2.0.2",
    "@types/node": "6.0.60",
    "aspnet-webpack": "3.0.0",
    "autoprefixer": "7.2.6",
    "circular-dependency-plugin": "4.4.0",
    "codelyzer": "4.0.1",
    "copy-webpack-plugin": "4.4.3",
    "cross-env": "5.0.5",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "1.1.11",
    "font-awesome": "4.7.0",
    "html-webpack-plugin": "2.30.1",
    "istanbul-instrumenter-loader": "3.0.1",
    "less-loader": "4.1.0",
    "npm-font-open-sans": "1.0.3",
    "popper.js": "1.14.3",
    "postcss-import": "11.1.0",
    "postcss-loader": "2.1.6",
    "postcss-url": "7.3.2",
    "raw-loader": "0.5.1",
    "rxjs-tslint": "0.1.5",
    "rxjs-tslint-rules": "4.7.2",
    "sass-loader": "6.0.7",
    "style-loader": "0.19.1",
    "stylus-loader": "3.0.2",
    "ts-node": "4.1.0",
    "tslint": "5.9.1",
    "tslint-clean-code": "0.2.3",
    "tslint-consistent-codestyle": "1.11.1",
    "tslint-eslint-rules": "5.0.0",
    "tslint-sonarts": "1.4.0",
    "typescript": "2.4.2",
    "uglifyjs-webpack-plugin": "1.2.7",
    "url-loader": "0.6.2",
    "webpack": "3.11.0",
    "webpack-cli": "3.0.8",
    "webpack-dev-server": "2.11.2"
  }
}

我们总是在任何构建之前刷新 node_modules 文件夹(nuke + npm install),并且错误最近出现(大约在上周一 2018-08-29)。

自上次构建以来,我们未对软件包版本进行任何更改。

没有 AOT 的构建仍然可以正常工作,没有任何错误。

如何解决这个错误?

只需从 package.json 文件中删除这一行:

"@telerik/kendo-intl": "1.3.2",

经过一番研究,我们发现在kendo-intl相关模块中定义了territoryFromName

似乎在 kendo 包中存在一些依赖性混乱,看起来 @telerik 包只是重新定义了 @progress kendo-angular 最近的依赖性包。

据我了解,这与我们的 @progress/kendo-angular-intl

有冲突

我一直在寻找我的应用程序有什么问题,因为我最近没有做任何更新,但仍然面临这个错误!

文件内: \node_modules\@telerik\kendo-intl\dist\es\cldr\territory.js

函数 territoryFromName 有一个重复声明,一个只有 name 作为参数,另一个有两个参数 name & identity

第一个没有用,我只是将其从文件中删除并保存,效果很好。

PS。我相信他们会很快修复这个错误,但现在这对我有用。

我也运行陷入这个错误。我没有在我的 package.json 中明确安装 @telerik/kendo-intl。它作为 @progress/kendo-angular-intl 版本 @1.4.1 的依赖项安装。

我 npm 安装了 @telerik/kendo-intl 到最新版本 @1.4.2 并且这解决了我的错误。 @Nour - 如果你看看 @1.4.1@1.4.2 之间的区别,你会注意到 Kendo 团队删除了重复的声明。