2017-04-23 132 views
2

我与聚合物的1.x一会儿工作,我想从头开始一个项目与聚合物2.0,但我得到了许多错误。我正在构建一个PWA,因为我包含了一个服务工作者和一个manifest.json文件。我得到的错误是,我认为,大多数版本之间的不兼容的,因为他们声称一些类的话(第二个错误等)定义的或不确定的“窗口”对象聚合物2.0错误

适用版本我遵循这个指南(点:升级现有项目)

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" 
    } 
} 

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

回答

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 : './') 

我希望帮助。

+0

感谢您的文章。你的修补程序是否消除了这两个错误,或者只是第一个?我试图追查第二个错误的原因(在'风格util.js中:243'),其中我看到在不使用'铂sw'的应用程序。 – kjhughes