聚合物2.0错误

我已经使用Polymer 1.x一段时间了,我想从Polymer 2.0开始一个项目,但是我收到了很多错误。 我正在构建一个PWA,因为我包含了一个服务工作者和一个manifest.json文件。 我认为,我得到的错误大多数是版本之间的不兼容性,因为他们声称某些类没有定义或未定义“窗口”对象(如第二个错误)

对于我遵循本指南的版本(指向:升级现有项目)

https://www.polymer-project.org/2.0/docs/about_20#polymer-1-compatibility-layer

第一个错误:

platinum-sw-register.html:111 
Uncaught ReferenceError: HTMLImports is not defined at platinum-sw-register.html:111

Uncaught TypeError: Cannot read property 'nativeMethods' of undefined
    at pa (style-util.js:243)
    at p.u (style-properties.js:499)
    at k.T (scoping-shim.js:299)
    at k.styleElement (scoping-shim.js:243)
    at Object.styleElement (scoping-shim.js:52)
    at HTMLElement.connectedCallback (element-mixin.html:636)
    at HTMLElement.connectedCallback (legacy-element-mixin.html:81)

我有以下index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">

    <title>AppTest</title>

    <link rel="import" href="bower_components/app-layout/app-layout.html"/>
    <link rel="import" href="bower_components/platinum-sw/platinum-sw-elements.html"/>
    <link rel="manifest" href="manifest.json"/>
    <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
    <!-- <script src="bower_components/web-animations-js/web-animations.min.js" async></script> -->
    <link rel="import" href="bower_components/app-layout/app-drawer/app-drawer.html">
    <link rel="import" href="bower_components/app-layout/app-header/app-header.html">
    <link rel="import" href="bower_components/app-layout/app-toolbar/app-toolbar.html">
  </head>

  <body>
    <platinum-sw-register
      auto-register
      skip-waiting
      clients-claim
      reload-on-install
      href="sw-import.js">
      <platinum-sw-cache
        default-cache-strategy="networkFirst">
      </platinum-sw-cache>
    </platinum-sw-register>

    <app-header reveals>
      <app-toolbar>
        <div main-title>My app</div>
      </app-toolbar>
    </app-header>
    <app-drawer id="drawer" swipe-open></app-drawer>
  </body>

  <script>
  </script>
</html>

和我的bower.json

{
  "name": "polymer-2-carousel",
  "private": true,
  "dependencies": {
    "polymer": "Polymer/polymer#^2.0.0-rc.3",
    "platinum-sw": "PolymerElements/platinum-sw#2.0-preview",
    "app-layout": "PolymerElements/app-layout#2.0-preview"
  }
}

正如你所看到的应用程序是一个非常简单的框架(只是一个测试开始),所以不应该有太多的错误或调查找出错误的原因,但我不明白是什么问题以及如何修理它。 任何帮助将不胜感激。


我也发现了这个问题,所以我必须在bower-components/platinum-sw/platinum-sw-register.html文件中更改以下这些行:

value: document._currentScript ? document._currentScript.baseURI :
      (HTMLImports.importForElement ? HTMLImports.importForElement(document.currentScript).baseURI :
      (document.currentScript ? document.currentScript.baseURI : './'))

至:

value: document._currentScript ? document._currentScript.baseURI :
      (document.currentScript ? document.currentScript.baseURI : './')

我希望有所帮助。

链接地址: http://www.djcxy.com/p/5329.html

上一篇: Polymer 2.0 errors

下一篇: Is it possible to share mixins across web components (and imports) in Polymer?