Using dart2js output with Cloud Code by


First, I transpose the javascript example into a dart one.


Parse.Cloud.define('hello', function(request, response) {
  response.success('Hello world');


import 'dart:js' show allowInterop;
import 'package:js/js.dart' show JS;

external void define(String name, Function func);

void main() {
  define('hello', allowInterop((req, res) {

Then I compile it using dart2js (with csp or not).

Finally I run parse deploy and I get

ReferenceError: self is not defined
    at <error: TypeError: Object #<error> has no method '__lookupGetter__'>
    at main.js:2539:9
    at init.currentScript (main.js:2519:7)
    at main.js:2534:5
    at main.js:2542:3

and now, here I am…

How I could get it work on which is a nodejs env I presume.


self is effectively not defined in the environement provided by, so I defined self such as var self = this; in the dart2js output.

I get a new error, about success$1 is not defined. Well, that’s true, my code is still incomplet…

Dart code should like this:

import 'dart:js' show allowInterop;
import 'package:js/js.dart' show JS, anonymous;

external void define(String name, Function func);

class HttpResponse {
  external void success(String msg);
  external void error(String msg);

void main() {
  define('hello', allowInterop((req, HttpResponse res) {

Now, everything work. I can enjoy my sunday.

Answered By – Druxtan

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

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