-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
[Flutter 3.22.0] [dart:js_interop] - "ExternalDartReference" and "toExternalReference" usage causes "flutter test" to fail due to "Dart library 'dart:js_interop' is not available on this platform." #148670
Comments
I've updated the code sample to not use any external dependencies so it's simpler to test. |
Further testing reveals that this can happen with any class or extension method from 00:00 +0: loading /Users/ricardodurao/repositories/sample_error_test/test/widget_test.dart lib/main.dart:1:8: Error: Dart library 'dart:js_interop' is not available on this platform.
import 'dart:js_interop';
^
Context: The unavailable library 'dart:js_interop' is imported through these packages:
/Users/ricardodurao/repositories/sample_error_test/test/widget_test.dart => package:sample_error_test => dart:js_interop
Detailed import paths for (some of) the these imports:
listener.dart => /Users/ricardodurao/repositories/sample_error_test/test/widget_test.dart => package:sample_error_test/main.dart => dart:js_interop
lib/main.dart:2:8: Error: Dart library 'dart:js_interop_unsafe' is not available on this platform.
import 'dart:js_interop_unsafe';
^
Context: The unavailable library 'dart:js_interop_unsafe' is imported through these packages:
/Users/ricardodurao/repositories/sample_error_test/test/widget_test.dart => package:sample_error_test => dart:js_interop_unsafe
Detailed import paths for (some of) the these imports:
listener.dart => /Users/ricardodurao/repositories/sample_error_test/test/widget_test.dart => package:sample_error_test/main.dart => dart:js_interop_unsafe
lib/main.dart:11:9: Error: Type 'JSAny' not found.
final JSAny reference;
^^^^^
lib/main.dart:44:13: Error: The getter 'toJS' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'toJS'.
'hello'.toJS,
^^^^
lib/main.dart:11:9: Error: 'JSAny' isn't a type.
final JSAny reference; |
Hi @r-durao-pvotal, You can run the test successfully by running You will need to employ the use of conditional imports if you want to use the js_interop library in a flutter app with targets other than web. Does the above information resolve your issue? |
Indeed, it does resolve it. Thank you! |
Steps to reproduce
flutter create
flutter test
Expected results
flutter test
shouldn't fail because of existingdart:js_interop
'sExternalDartReference
andtoExternalReference
in source codeActual results
flutter test
fails because ofdart:js_interop
'sExternalDartReference
andtoExternalReference
(see error logs). Should we not use these in our flutter code?Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: