Skip to content

[js_interop]: "Uncaught TypeError: J.d5(...).Y is not a function" when importing "dart:js_util" library together #44150

@jumperchen

Description

@jumperchen

Dart version: 2.9.3~2.10.2

When using @JS() js_interop with a Dart class like Win in js_interop.dart and importing the library dart:js_util in main.dart together, all the methods defined inside Win will be lost in Dart2JS compiler.

For example,

main.dart

import 'dart:js_util';
import 'js_interop.dart';

main () {
   
    /// The following code only works separately
    window.eval('console.log("test")');
    callMethod(window, 'eval', ['console.log("test2")']);
}

As you can see, if we comment out either line in the main function, it works well with Dart2JS compiler.

js_interop.dart

@JS()
library dart.issue.js;

import 'package:js/js.dart';

@JS()
@anonymous
abstract class Win {
  external eval(String script);
}

@JS()
external Win get window

Here is a whole test project to demonstrate this issue - https://github.com/jumperchen/dart_interop_bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions