Polymer 2.x 构建错误 - class 的多个全局声明和标识符 Polymer.Element

Polymer 2.x Build Error - Multiple global declarations of class with identifier Polymer.Element

对于我在 Polymer 2.x 项目中定义的每个元素,我收到以下警告:

Multiple global declarations of class with identifier Polymer.Element

构建最终失败,并在 ...\node_modules\polymer-build\lib\analyzer.js

处被 Promise 拒绝

这些组件是否定义不当?

如何正确构建项目?

我的 polymer.json 文件是

{
  "entrypoint": "index.html",
  "shell": "src/shop-app.html",
  "fragments": [
    "src/lazy-resources.html"
  ],
  "sources": [
    "src/**/*",
    "data/**/*",
    "images/**/*",
    "app.yaml",
    "bower.json",
    "manifest.json",
    "sw-precache-config.js",
    "Web.config"
  ],
  "extraDependencies": [
    "manifest.json",
    "bower_components/webcomponentsjs/webcomponents-lite.js"
  ],
  "lint": {
    "rules": ["polymer-2-hybrid"]
  },
  "builds": [{
    "js": {"minify": true},
    "css": {"minify": true},
    "html": {"minify": true}
  }]
}

此错误意味着您从两个不同的网址加载了相同的依赖项。例如

myStuff/myApp.html
myOtherStuff/myApp.html

我在构建 Polymer 2 应用程序时遇到了同样的警告。可能是因为我的一些元素导入了相同的其他元素,并且所有元素都扩展了 Polymer.Element。我已经检查了所有元素是否有重复导入。可能有些第三方元素有重复,但我的元素没有。

所以我在 polymer.json 中将警告添加到忽略列表中:

{
  "lint": {
    "rules": [
      "polymer-2"
    ],
    "ignoreWarnings": ["multiple-global-declarations"]
  },
  ...
}

我也有同样的警告,在清理 bower_componentsnode_modules 后它就消失了。