dart2js's output causes "null is not an object"

Issue

After running

private/dart/dart-sdk/bin/dart2js -m -o public/js/script.js private/dart/script.dart

The resulting javascript returns

TypeError: 'null' is not an object (evaluating 'J.RE(a).gVs')

However, the error while not minified is

TypeError: 'null' is not an object (evaluating 'J.getInterceptor$x(receiver).get$onBlur')

Which might be more meaningfull.

It does this whether I use script.js, or script.compiled.js.

The dart code is

import 'dart:html';
import 'dart:core';

void main() {
   querySelector("#authorInput").onBlur.listen(updateSurname);
}
void updateSurname(Event e){
   String author = (e.target as InputElement).value;
   String surname = author.split(' ').last;
   querySelector("#surnameInput").text = surname;
}

The relevant haml is

  .form-group
     %label(for="authorInput") Author
     %input.form-control#authorInput(type="text" name="author" placeholder="Enter author")
  .form-group
     %label(for="surnameInput") Surname
     %input.form-control#surnameInput(type="text" name="surname" placeholder="Enter surname")

I believe it should work as is, though that’s clearly not the case.

Solution

Figured it out.

I included the compiled javascript file inside the tag of the html page. Moving it to the very bottom of the body fixed everything.

Answered By – Cereal

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *