Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

dart - js interop compiled with dart2js error - Uncaught NoSuchMethodError : method not found:

I generated a sample Polymer web project. Added following js file.

jslib.js

function testfunction()
{
alert("test");
}

in clickcounter.dart I added dependency

import 'package:js/js.dart' as js; 

and changed increment() function

void increment() {
    js.context.testfunction();
    count++;
}

In clickcounter.html added js file import

<script src="jslib.js" type="text/javascript"></script>

And in main html file added

<script src="packages/browser/interop.js"></script>

It works correctly when in executed in Dartium. When I compile it to javascript however it gives an error

Uncaught NoSuchMethodError : method not found: 'Symbol("testfunction")'
Receiver: Instance of 'Proxy'
Arguments: [] js_helper.dart:870


Stack Trace:
Error
at Object.wrapException (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:4632:13)
at Proxy.Object.noSuchMethod$1 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:33708:13)
at Proxy_noSuchMethod_closure.call$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109612:46)
at Object.Proxy.static.Proxy__forward (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109581:45)
at Proxy.noSuchMethod$1 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109492:14)
at Proxy.Object.testfunction$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:56090:17)
at ClickCounter.increment$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:7080:50)
at CachedInvocation.invokeOn$2 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:6221:28)
at JsInstanceMirror._invoke$4 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:12998:35)
at JsInstanceMirror.invoke$3 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:12963:17)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try putting your reference to interop.js above that of the compiled dart file and dart.js:

<script type="text/javascript" src="path/to/interop.js"></script>
<script type="text/javascript" src="path/to/main.dart.js"></script>
<script type="text/javascript" src="path/to/dart.js"></script>

I learned this from Dart Issue # 15065 and it resolved a similar error I had with the dart:js library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...