Skip to content
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

browser_client.dart - Error: Not found: 'dart:html' #36318

Closed
mtcliatt opened this issue Mar 23, 2019 · 4 comments
Closed

browser_client.dart - Error: Not found: 'dart:html' #36318

mtcliatt opened this issue Mar 23, 2019 · 4 comments

Comments

@mtcliatt
Copy link
Contributor

I'm attempting to use the html WebSocket class, which resolves in IntelliJ, but won't build.

I'm even able to jump to the source of WebSocket from my code.

This seemed similar to #35973, so I performed the recommended fix for a corrupted Flutter installation, to no avail. See flutter doctor output below.


Dart SDK Version: Dart VM version: 2.1.2-dev.0.0.flutter-0a7dcf17eb (Tue Feb 12 01:59:15 2019 +0000) on "windows_x64"

OS: Windows 10


Error output:

lib/src/alpaca_streaming_client.dart:2:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
file:///C:/Users/matth/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/http-0.12.0+1/lib/src/browser_client.dart:6:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
lib/src/alpaca_streaming_client.dart:40:23: Error: Type 'MessageEvent' not found.
  void _handleMessage(MessageEvent message) {
                      ^^^^^^^^^^^^
file:///C:/Users/matth/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/http-0.12.0+1/lib/src/browser_client.dart:95:25: Error: Type 'HttpRequest' not found.
  void _openHttpRequest(HttpRequest request, String method, String url,
                        ^^^^^^^^^^^
file:///C:/Users/matth/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/http-0.12.0+1/lib/src/browser_client.dart:30:25: Error: 'HttpRequest' isn't a type.
  final _xhrs = new Set<HttpRequest>();
                        ^^^^^^^^^^^
lib/src/alpaca_streaming_client.dart:19:20: Error: Method not found: 'WebSocket'.
    final socket = WebSocket(url);
                   ^^^^^^^^^
lib/src/alpaca_streaming_client.dart:19:20: Error: The method 'WebSocket' isn't defined for the class 'AlpacaStreamingClient'.
 - 'AlpacaStreamingClient' is from 'package:alpaca_dart/src/alpaca_streaming_client.dart' ('lib/src/alpaca_streaming_client.dart').
Try correcting the name to the name of an existing method, or defining a method named 'WebSocket'.
    final socket = WebSocket(url);
                   ^^^^^^^^^
lib/src/alpaca_streaming_client.dart:40:23: Error: 'MessageEvent' isn't a type.
  void _handleMessage(MessageEvent message) {
                      ^^^^^^^^^^^^
file:///C:/Users/matth/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/http-0.12.0+1/lib/src/browser_client.dart:44:19: Error: Method not found: 'HttpRequest'.
    var xhr = new HttpRequest();
                  ^^^^^^^^^^^
file:///C:/Users/matth/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/http-0.12.0+1/lib/src/browser_client.dart:55:45: Error: Method not found: 'Blob'.
      var blob = xhr.response == null ? new Blob([]) : xhr.response;
                                            ^^^^

Flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.2)
[√] IntelliJ IDEA Community Edition (version 2018.3)
[√] VS Code (version 1.32.3)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.
@DanTup
Copy link
Collaborator

DanTup commented Mar 28, 2019

I believe the dart:html library is for web apps only (it wraps the DOM APIs) and won't work in Flutter. There's some info on using Web Sockets in Flutter using the web_socket_channel package on the Flutter site:

https://flutter.dev/docs/cookbook/networking/web-sockets#1-connect-to-a-websocket-server

@mtcliatt
Copy link
Contributor Author

mtcliatt commented Apr 1, 2019

Thanks Dan, but I'm trying to use this in a pure Dart package, without Flutter.

How can I use WebSockets in a pure Dart package?

Also, I don't see anything in the docs that would make it apparent the dart:html library is for web apps only. Should we update that?

@DanTup
Copy link
Collaborator

DanTup commented Apr 1, 2019

@mtcliatt Gotcha! You need to use a standard Dart SDK for that - the one that was included with/downloaded by Flutter won't work. You can get the standard SDK (which includes all the web bits) from https://www.dartlang.org/tools/sdk.

That said - if you're writing a command-line/server app (not browser bsed), then you'll still need to avoid the dart:html library. There's some info here that says "Only web apps can use dart:html, not command-line apps".

@kevmoo
Copy link
Member

kevmoo commented Apr 3, 2019

We try to make it clear here – https://api.dartlang.org/stable/2.2.0/index.html

That there are a set of libraries that only work on the web.

Sorry for the confusion!

@kevmoo kevmoo closed this as completed Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants