Exception: NoSuchMethodError: method not found: &#

2019-02-24 07:50发布

问题:

I am using Dart SDK 1.5.3 | polymer 0.11.0+5 | Windows x64. When I create a created a polymer application using the template 'Sample web application using the polymer library (mobile friendly) option' and run the application it works as expected with the counter incrementing when the button is clicked.

Assuming the page with the

<script type="application/dart">
  export 'package:polymer/init.dart';
</script>

is index.html, attempting to refactor the application by removing the following lines from index.html

<click-counter count="5"></click-counter>
<link rel="import" href="clickcounter.html">

results in the following error:

Exception: NoSuchMethodError: method not found: 'whenPolymerReady'
Receiver: Instance of 'JsFunction'
Arguments: [Closure: () => dynamic] (package:polymer/src/loader.dart:115)
Breaking on exception: NoSuchMethodError: method not found: 'whenPolymerReady'

I have used the mechanism all the time in creating any polymer app, but has never seen such exception although I have seen documentation on the web involving Dart https://www.google.com.jm/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CBwQFjAA&url=http%3A%2F%2Fcode.google.com%2Fp%2Fdart%2Fissues%2Fdetail%3Fid%3D19161&ei=MZq8U_nlK42KyASBkYHgCw&usg=AFQjCNHOc6MD-mhzPbDOmg8Hp5NeqVufqQ&bvm=bv.70138588,d.aWw

The documentation suggested that this problem had resolved but it certainly is present in the current polymer I am using.

回答1:

Each of your components (each file containing a <polymer-element> tag) must import polymer.html.

Make sure your clickcounter.html contains the line:

<link rel="import" href="packages/polymer/polymer.html" />

at the top. (It was breaking change in 0.11).



回答2:

I'm clueless about these things, but for me I seemed to solve it by moving the following code:

<!-- after the Polymer elements imports -->
<script type="application/dart">export 'package:polymer/init.dart';</script>    
<script async src="packages/browser/dart.js"></script>

from the end of the <head>er, to just before the </body>. Only my index.html now contains these lines. Lastly I also moved my custom element import above core-elements/paper-elements imports.



回答3:

My dummy application created from the polymer template starts fine, but once I move the clickcounter to another directory, I start getting this error (I have updated references accordingly). My new folder structure is the following:

/lib
  /src
    /test
       clickcounter.dart
       clickcounter.html
/web
  polytest.html 

This is how the modified line looks:

    <link rel="import" href="../lib/src/test/clickcounter.html">


回答4:

I think I found the solution.

The clickcounter.html |imports link rel="import" href="packages/polymer/polymer.html|". In the entry-point file, there is no such import. When a component is imported into the entry-point, it seems that the polymer.html condition is satisfied. In the absence of a component the import has to placed directly in the file.

    <!DOCTYPE html>

    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Sample app</title>
        <!-- <script src="packages/web_components/platform.js"></script>
             not necessary anymore with Polymer > 0.14.0 -->
        <script src="packages/web_components/dart_support.js"></script>

        <link rel="import" href="packages/polymer/polymer.html">

        <script type="application/dart">export 'package:polymer/init.dart';</script>
        <script src="packages/browser/dart.js"></script>


        <link rel="stylesheet" href="epimss_material_design.css">
      </head>
      <body>
        <h1>Epimss material design</h1>

        <p>Hello world from Dart!</p>

        <div id="sample_container_id">

        </div>

      </body>
    </html>

After that everything worked fine.

The same problem actually resurfaced in Dart SDK 1.6.0-dev.1.2 and was similarly solved. Still, I cannot say if its a bug or not. It simply works by adding this import. I suppose if a legitimate component is used that imports would allow the removal of the same import from the entry-point file. One of Dart or Dart-polymer expert might be able to explain what actually is happening. Looking forward to the in-depth explanation since this is the first time I have observed this issue.



回答5:

I just ran into the same issue. Are you sure your polymer imports are underneath your javascript imports?

<!-- <script src="packages/web_components/platform.js"></script>
     not necessary anymore with Polymer 0.14.0 -->
<script src="packages/web_components/dart_support.js"></script>
<!-- import the click-counter -->
<link rel="import" href="clickcounter.html">

instead of:

<!-- import the click-counter -->
<link rel="import" href="clickcounter.html">
<script src="packages/web_components/platform.js"></script>
<script src="packages/web_components/dart_support.js"></script>


回答6:

I'm not in that development, but it seems like your problem is API or dependencies used in application.



回答7:

I think your transformer settings is missing the entry page

transformers:
- polymer:
    entry_points:
    - example/index.html

Otherwise look closely at the output if there is any other warning or error that points to the root causel



回答8:

I've just had exactly the same issue. It looked like the code stopped working without any change performed by me.

Root cause of the issue was, that there appeared a new version of polymer package.

So you should probably play with dependencies in your pubspec.yaml. I just explicitly changed the version of Polymer to some older one.