vickumar1981/jupyter-dart-kernel

Failing to Import

Closed this issue · 6 comments

Hi,

I managed to install the kernel and can run basic dart code. However I am struggling with importing standard dart classes e.g.:

import 'dart.math';

produces the following error:

/tmp/tmprdl0ihly/main.dart:3:1: Error: Expected ';' after this.
import 'dart:math';
^^^^^^
/tmp/tmprdl0ihly/main.dart:3:1: Error: Undefined name 'import'.
import 'dart:math';
^^^^^^

I have made sure that dart is installed and have added the path to dartkernel.py to my PYTHONPATH environment variable. Still no joy. I have my jupyter notebook running on Ubuntu 20. Please help.

Regards,

@chibsta thank you for reporting this error.

Took a stab at fixing the import issue: e3e5918

I tested and it seemed to work now. Let me know if this works for you.

basic issue is that i copied this code from the swift kernel, but swift can run as a script, whereas dart expects some kind of main method, like Java and C.

it was just putting all the code inside a main method that dart expects:

void main() {
  [your code here]
}

not sure if this is the best approach, but now it reads the start of each line and splits them as either import statements or code statements. i.e.,

[import statements]
void main {
  [code statements]
}

Fantastic! Thanks @vickumar1981. Sorted!!

@chibsta is it okay if i close this issue out as resolved?

Resolved! Thanks once again!

Resolved by: e3e5918