2

我使用 Polymer 1.x 已经有一段时间了,我想使用 Polymer 2.0 从头开始​​一个项目,但我遇到了很多错误。我正在像以前一样构建 PWA,因此我包含了一个 service worker 和一个 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"
  }
}

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

4

1 回答 1

1

我也发现了这个问题,所以我必须在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 : './')

我希望这会有所帮助。

于 2017-04-25T03:38:15.847 回答