Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError when compiling working Dart project to js. #15125

Closed
DartBot opened this issue Nov 17, 2013 · 9 comments
Closed

Uncaught TypeError when compiling working Dart project to js. #15125

DartBot opened this issue Nov 17, 2013 · 9 comments
Labels
closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Nov 17, 2013

This issue was originally filed by cyrill.zadr...@gmail.com


What steps will reproduce the problem?

  1. Attached MpisMobile project runs fine in DartVm
  2. Build project (compile to javascript)
  3. Run mpismobile.html with browser

What is the expected output? What do you see instead?
It should show a map with default location in zurich. Map stays grey and in browser console following error is shown:

Uncaught TypeError: Cannot call method 'get$map' of null mpismobile.html_bootstrap.dart.js:142561

What version of the product are you using? On what operating system?

Dart Editor version 1.0.0_r30187 (DEV)
Dart SDK version 1.0.0.3_r30187
Chrome 31
Firefox 25
IE 10

Please provide any additional information below.
Dart project example can be also found on https://github.com/thomasfrick1/mpis/tree/dart2js-problem/MpisMobile


Attachment:
MpisMobile.zip (5.07 MB)

@DartBot
Copy link
Author

DartBot commented Nov 19, 2013

This comment was originally written by michael.haubenwa...@gmail.com


This might be some timing problem with querySelector.

I had the same problem and after moving the script element with the compiled JS from HEAD to the bottom of the document BODY it worked for me again.

@DartBot
Copy link
Author

DartBot commented Nov 20, 2013

This comment was originally written by michael.haubenwa...@gmail.com


When compiling the sample content for a dart web application, this comes up in the resulting JS file:

TypedData_ListMixin_FixedLengthListMixin: {"": "TypedData_ListMixin+FixedLengthListMixin;", $asList: null}}],
["", "webappsample.dart", , R, {
main: function() {
  var t1, t2;
  t1 = document.querySelector("#sample_text_id");
  t1.textContent = "Click me!";
  t1.toString;
  t1 = new W._ElementEventStreamImpl(t1, C.EventStreamProvider_click._eventType, false);
  H.setRuntimeTypeInfo(t1, [null]);
  t2 = new W._EventStreamSubscription(0, t1._target, t1._eventType, W._wrapZone(R.reverseText$closure), t1._useCapture);
  H.setRuntimeTypeInfo(t2, [H.getRuntimeTypeArgument(t1, "_EventStream", 0)]);
  t2._tryResume$0();
},

reverseText: function($event) {
  var text, buffer, i, t1;
  text = document.querySelector("#sample_text_id").textContent;
  buffer = P.StringBuffer$("");
  for (i = text.length - 1; i >= 0; --i) {
    t1 = text[i];
    buffer._contents = buffer._contents + t1;
  }
  document.querySelector("#sample_text_id").textContent = buffer._contents;
}},
1],
]);

Question is, if "t1.toString;" is used to test for a null/unassigned value of "t1" or is just test output and not removed from the compiler?

@sethladd
Copy link
Contributor

Added Area-Dart2JS, Triaged labels.

@peter-ahe-google
Copy link
Contributor

Pete: I believe that dart2js is doing the right thing by executing main before the rest of the DOM is parsed (leading to querySelector returning null).

Michael: re #­3, yes dart2js will insert t1.toString to check for null. But in this case it seems redundant (as it is preceded by t1.textContent).


Set owner to @blois.

@blois
Copy link
Contributor

blois commented Nov 21, 2013

Correct- the execution is occurring in the head.

The proper fix would be to modify mpismobile.html to move the Dart script to the end of the body tag.

I just opened 15229 against Polymer build- it should either be adding a defer attribute to the generated JS script, or it should add a warning when the script is not at the end of the body (or both).


Added AsDesigned label.

@DartBot
Copy link
Author

DartBot commented Nov 21, 2013

This comment was originally written by cyrill....@gmail.com


Thanks for looking into this issue. I just tried out your described workaround and moved <script type="application/dart" src="mpismobile.dart"></script> to the bottom of mpismobile.html.

Tried it with following to examples.

<html>
  ....
  <mpis-maps id="myMap"></mpis-maps>
  
  <script type="application/dart" src="mpismobile.dart"></script>
 
</body>
</html>

or

<html>
  ....
  <mpis-maps id="myMap"></mpis-maps>
  
  <script src="packages/browser/interop.js"></script>
  <script src="http://maps.googleapis.com/maps/api/js?sensor=false">&lt;/script>
  <script type="application/dart" src="mpismobile.dart"></script>
  <script src="packages/browser/dart.js"></script>
  
</body>

In both cases I get this js error.

[10:50:36.800] : NoSuchMethodError : method not found: 'Symbol("map")'
Receiver: Instance of 'UnknownElement'
Arguments: [] @­ file:///C:/dev/projects/eth/mpis/MpisMobile/build/mpismobile.html_bootstrap.dart.js:3894

It's a different error .. so shall I open a different issue here? Or post my problem somewhere else?

@peter-ahe-google
Copy link
Contributor

cc @blois.
cc @rakudrama.
Removed the owner.
Added Triaged label.

@peter-ahe-google
Copy link
Contributor

I've filed issue #15236 regarding the redundant null check.

@matanlurey
Copy link
Contributor

PolymerDart is deprecated.

@matanlurey matanlurey added closed-obsolete Closed as the reported issue is no longer relevant and removed web-dart2js labels Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants