0

I've seen plenty of other similar errors, but I'm not sure if they are related or not. I'm basically trying to dynamically create polymer components and add them to the existing page, once that is working, I want to create my own Polymer components and dynamically add / remove them to and from the page.

pubspec.yaml:

name: alm
description: alm
dependencies:
  browser: any
  polymer: ">0.15.3"
  paper_elements: any
transformers:
- polymer:
    entry_points:
      - web/index.html

index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>  
    <link rel="import" href="packages/paper_elements/paper_button.html">    
  </head>
  <body unresolved>   
    <script type="application/dart" src="index.dart"></script>    

    <paper-button raised class="colored">colored</paper-button>
    <paper-button raised disabled>disabled</paper-button>

    <div id="more-buttons"></div>

    <script src="packages/browser/dart.js"></script>
  </body>
</html>

index.dart:

import 'dart:html';
import 'package:polymer/polymer.dart';
import 'package:paper_elements/paper_input.dart';
void main(){

  initPolymer().run(() {
    Polymer.onReady.then((_) {     
      DivElement div =   querySelector("#more-buttons");
      div.appendText("text 1 2 3");
      PaperInput pinput = new PaperInput.created();
      div.append(pinput);      
    });
  });

}

The exception I'm getting:

Breaking on exception: type 'HtmlElement' is not a subtype of type 'PaperInput' of 'function result'.

If I try using the Element object:

  Element y = new Element.tag('paper-input');
  div.append(y);

Breaking on exception: type 'HtmlElement' is not a subtype of type 'PaperInput' of 'function result'.

Exception: type 'HtmlElement' is not a subtype of type 'PaperInput' of 'function result'. (package:paper_elements/paper_input.dart:40)

I'm also curious why everything is so massive:

enter image description here

I'm using the standard dart editor and click run in Dartium to run the application.

Update:

I've updated the code, getting different errors now. Had to update the polymer version in pubspec.yaml, any was causing errors.

Browser Console:

Failed to load resource: the server responded with a status of 404 (Not Found)
  http://localhost:8080/packages/web_components/webcomponents.js
Failed to load resource: the server responded with a status of 404 (Not Found)
  http://localhost:8080/packages/web_components/interop_support.html
Failed to load resource: the server responded with a status of 404 (Not Found)
  http://localhost:8080/packages/custom_element_apigen/src/common.dart
An error occurred loading file: package:custom_element_apigen/src/common.dart

What I'm seeing now is a brief flash of the buttons followed by a white screen.

Tools output is giving me the following error:

Resolving dependencies...
Got dependencies!


--- 6:10:00 PM Starting pub serve : ______ ---
Loading source assets...
Loading polymer transformers...
Serving alm web on http://localhost:8080
[Warning from ImportInliner on alm|web/index.html]:
line 10, column 1 of package:paper_elements/src/polymer/polymer.html: Failed to inline HTML import: Could not find asset web_components|lib/interop_support.html.
null. See http://goo.gl/5HPeuP#polymer_25 for details.
<link rel="import" href="../../../../packages/web_components/interop_support.html">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Build completed successfully

Looking at the suggested link:

Error while inlining an import
An error occurred while inlining an import in the polymer build. This is often the result of a broken HTML import.

I can't really see what could be wrong with my index.html and that import I can see under the paper_elements package.

Update2:

Updated version of polymer to >0.15.3 and also ran pub upgrade and pub cache repair now seeing a different exception:

Exception: Uncaught Error: created called outside of custom element creation.
Stack Trace:
#0      Blink_Utils.initializeCustomElement (dart:_blink:31040)
#1      _Utils.initializeCustomElement (dart:html:41640)
#2      _initializeCustomElement (dart:html:41835)
#3      Element.Element.created (dart:html:11675)
#4      HtmlElement.HtmlElement.created (dart:html:17615)
#5      HtmlElement&DomProxyMixin.HtmlElement&DomProxyMixin.created (package:paper_elements/paper_input.dart:4:1)
#6      HtmlElement&DomProxyMixin&PolymerProxyMixin.HtmlElement&DomProxyMixin&PolymerProxyMixin.created (package:paper_elements/paper_input.dart:4:1)
#7      PaperInput.PaperInput.created (package:paper_elements/paper_input.dart:39:26)
#8      main.<anonymous closure>.<anonymous closure> (http://localhost:8080/index.dart:12:31)
#9      _RootZone.runUnary (dart:async/zone.dart:1155)
#10     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:484)
#11     _Future._propagateToListeners (dart:async/future_impl.dart:567)
#12     _Future._completeWithValue (dart:async/future_impl.dart:358)
#13     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:412)
#14     _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#15     _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#16     _handleMutation (dart:html:41819)

Seems to work fine for paper-button, button actually displays:

  PaperButton y = new PaperButton();
  y.text = "KOTS";
  y.raised = true;
  div.append(y);

Maybe a bug in paper-element, will investigate and log a bug if needed.

Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137

1 Answers1

1

The tranformer config misses the entry_page setting and the custom main method is incomplete for polymer apps (see https://stackoverflow.com/a/20982658/217408)
Sorry for the short answer, I'm on my phone.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I've updated the code and the question, fixing those errors brought along other errors that causes nothing to load. Also, what is the latest version of polymer I can use in dart? The docs suggested 0.12 - 0.13, but I've seen greater version numbers in samples floating around the web. – Jan Vladimir Mostert Dec 16 '14 at 16:21
  • 1
    0.15.3 is the latest as far as I remember and you can and shoul use it. To get rid of the errors update to a more recent version by specifying a minimum version in pubspec.yaml, run `pub upgrade` and if you still get similar errors run `pub cache repair` on the command line. – Günter Zöchbauer Dec 16 '14 at 16:32
  • I'm not sure where to get pub from, so I simlinked it from the dart editor to `/usr/bin/pub`, ran `pub upgrade` and `pub cache repair` after updating the dart version. Getting a big stack trace now, at least the buttons and text are loading now, although still massive as in the screenshot. – Jan Vladimir Mostert Dec 16 '14 at 16:58
  • 1
    The `created` constructor is definitively the wrong way to create a new Polymer element. There should be a generated factory constructor but I don't know how it is named. `element.tag` should now work too after you fixed your main method. – Günter Zöchbauer Dec 16 '14 at 17:09
  • When using the Element.tag, I can see the `` element if I do an inspect element, but it's not usable like that. I'm guessing this is not the right way to do it either? I'm browsing through the code of paper_input.dart and I see it extends HtmlElement which is in a massive ~42000 loc file. Does factory methods exist for creating polymer components via dart code or should this be avoided? I can't immediately see factory methods that would create usable polymer components for me via dart. – Jan Vladimir Mostert Dec 16 '14 at 18:17
  • It actually works fine for buttons, must be a bug in the paper-input tag. Will investigate and log a bug if needed. – Jan Vladimir Mostert Dec 16 '14 at 18:23
  • I looked it up and you can create a new PaperInput with just `new PaperInput()` (the same for other core- and paper-elements. – Günter Zöchbauer Dec 16 '14 at 20:05
  • Mixing polymer elements in HTML and dart causes other bizarre problems, I'm managing to reproduce bugs that were fixed in earlier versions, having problems with browser crashes, in some instances my main method is called multiple times breaking Polymer's init. It's still a little too rough around the edges for usage in something that needs to go into production 6 months from now. Straight bootstrap (bootjack also looks interesting) with dart seems to be a somewhat more stable combination for now, will keep Polymer-dart for my toy-projects for now. Thanks for the help Günter! – Jan Vladimir Mostert Dec 16 '14 at 20:41
  • If you still call `created` I'm not surprised. Polymer.dart works quite well if you avoid certain don'ts. – Günter Zöchbauer Dec 16 '14 at 21:12
  • Doing it the right way and getting these problems, will play some more tomorrow and see if I can work around the bugs, 1 day is probably not enough to decide. Having components in the frontend will save me tons of time in the future. – Jan Vladimir Mostert Dec 16 '14 at 21:35
  • Please update your question (or create a new one) to reflect the latest changes and add the errors you get and I'll have another look. – Günter Zöchbauer Dec 17 '14 at 06:32
  • It's mostly working today, I scrapped the old project and started a new one copying and pasting code snippets, the multiple calls to the main method disappeared, the oversized components fixed itself, the crashing browser problem went away, etc. Yesterday's `pub cache repair` and `pub upgrade` didn't fix it either. Today those problems are gone (very strange). Posted a new question: https://stackoverflow.com/questions/27519217/webcomponents-js-fails-with-error-404 – Jan Vladimir Mostert Dec 17 '14 at 07:00