I try to run in VSCode a simple dart program with
import 'dart:html';
clause.
import 'dart:html';
// import 'package:html/dom.dart';
// import 'package:html/dom_parsing.dart';
// import 'package:html/parser.dart';
void main() async{
var myTable = new TableElement()
..setAttribute('border','1');
// ..setAttribute(name, value);
...
In Run mode (I use VSCode extension "Code Runner 0.9.9") and in Debug appeared the same error:
Error: Not found: 'dart:html'
import 'dart:html';
I have installed Dart SDK 2.3.1 at Windows10 and not installed Flutter at all.
PATH pointed to Dart SDK bin directory
PATH =D:\Dart\dart-sdk\bin;
*) At project directory I try to add additional directive at pubspec.yaml
dependencies:
----
name: main
description: Test App sample22
dependencies:
html:
---
After "pub get" command I'll see that html present but error still persist.
pub get
Resolving dependencies...
+ charcode 1.1.2
+ csslib 0.16.0
+ html 0.14.0+2
+ path 1.6.2
+ source_span 1.5.5
+ term_glyph 1.1.0
Changed 6 dependencies!
*) My next step was to import html parts via "package:html/" (marked as comments in code sample). It is not helped and required class TableElement still unrecognizable.
"main.dart:8:19: Error: Method not found: 'TableElement'."
*) I try to change "launch.json" string from
default
"program": "bin/main.dart",
to
"program": "D:/Dart/WRK03t/main.dart",
And rename my code file to "main.dart"
*) Also I try to remove Dart extension from VSCode, restart PC and install it again. it's not helped.
But let me say that when I compile main.dart to js
"dart2js -m -o tst.js main.dart"
Resulted tst.js run correctly within the html page.
Almost the same problem in Request Dart Installation doesnt find dart:html
dart:html is only available in the browser. This is the error you get if you try to run code that uses it on the VM (instead of the browser). This is expected.
If you need to run your code outside of the browser (eg. in the VM as a CLI app or via Fluter) you cannot use dart:html. If you only want to use it in the browser but VS Code is trying to run your code in the VM, you'll need to set up some VS Code tasks/launch configs to run build_runner, similar to the Dart DevTools project:
https://github.com/flutter/devtools/tree/abe811f66e1bd36612b76bbe28250bc669a6ce08/.vscode
Related
I am trying to replace python with dart as a scripting language for my tools. I can create a python file anywhere, import global packages and run it but I can't seem to get this working with dart. Do I always need a pubspec.yaml file to run a dart script?
This is the script I am trying to run:
import 'package:http/http.dart' as http;
main(List<String> args) async{
var res = await http.get('https://example.com');
print(res.headers);
}
This is the error I am getting:
Error: Could not resolve the package 'http' in 'package:http/http.dart'.
test2.dart:1:8: Error: Not found: 'package:http/http.dart'
import 'package:http/http.dart' as http;
^
test2.dart:4:19: Error: Method not found: 'get'.
var res = await http.get('https://example.com');
No, you don't need a pubspec.yaml file to run a program, but it does need to somehow be able to resolve all the imports.
The pubspec.yaml file is used for obtaining the packages (from pub.dev, a git repository, etc.) but not for finding the packages at runtime. The pub program reads the pubspec.yaml file and downloads the packages mentioned in it, and maintains a packages specification file indicating where each package resolves to. By default the packages specification is in a file called .packages in the same directory as the pubspec.yaml file. The Dart runtime normally finds the packages by looking at the .packages package specification file, but there are other ways.
Here are some options:
Put a .packages file in the same directory as the Dart program, or in an ancestor directory.
Use the --packages option to specify the package specification file to use:
dart --packages=/home/username/stuff/mypackagespecfile myprogram.dart
The Dart runtime also has a --package-root option. But I haven't figured out how to make it work.
The import statements use URIs, so import 'file://...'; can also work in some cases.
Use dart2native to compile the program into an executable.
Note: Dart scripts can also start with a hash-bang line:
#!/usr/bin/env dart
import 'package:http/http.dart' as http;
main(List<String> args) async{
var res = await http.get('https://example.com');
print(res.headers);
}
Then you can make the program executable and run it without needing to type in the Dart runtime:
$ chmod a+x myprogram.dart
$ ./myprogram.dart
i have written simple script, which launches an chrome app on Android N(7.0),but not able to run, getting error
Details Environment
Appium version (or git revision) that exhibits the issue: 1.4.16.1
Last Appium version that did not exhibit the issue (if applicable): N/A
Desktop OS/version used to run Appium: window 7/32 bit
Node.js version (unless using Appium.app|exe): node-v8.9.4-x86
Mobile platform/version under test: chrome browser /64.0.3282.123
Real device or emulator/simulator:Android 7.0.0:MotoG(4)/Build/NPJS25.93-14-10
Appium CLI or Appium.app|exe: Appium Desktop exe
Error logs
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""\nadb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.unlock without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"cmd":"C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""","origValue":"Command failed: C:\Windows\system32\cmd.exe /s /c "D:\android-sdk\platform-tools\adb.exe -s ZY2239HZB2 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk""\nadb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.unlock without first uninstalling.]\r\n"},"sessionId":null}
code:
import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
//import org.testng.annotations.Test;
public class StartChrome
{
public static void main(String[] args) throws MalformedURLException{
DesiredCapabilities cd=DesiredCapabilities.android();
cd.setCapability(MobileCapabilityType.BROWSER_NAME,BrowserType.CHROME);
cd.setCapability(MobileCapabilityType.PLATFORM,Platform.ANDROID);
// we need to define platform name
cd.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
// Set the device name as well (you can give any name)
cd.setCapability(MobileCapabilityType.DEVICE_NAME,"my phone");
// set the android version as well
cd.setCapability(MobileCapabilityType.VERSION,"7.0");
// Create object of URL class and specify the appium server address
URL url= new URL("http://127.0.0.1:4723/wd/hub");
// Create object of AndroidDriver class and pass the url and capability that we created
WebDriver driver = new AndroidDriver(url, cd);
// Open url
driver.get("http://www.facebook.com");
// print the title
System.out.println("Title "+driver.getTitle());
// enter username
driver.findElement(By.name("email")).sendKeys("sni****#gmail.com");
// enter password
driver.findElement(By.name("pass")).sendKeys("*****8");
// click on submit button
driver.findElement(By.id("u_0_5")).click();
// close the browser
driver.quit();
Please update your Appium version as it's very old and you're seeing a known issue with Android 7.0 that was resolved in 1.6.0 (released October 2016).
If that's not possible, run the following commands before running your script:
adb -s device_serial uninstall io.appium.settings
adb -s device_serial uninstall io.appium.unlock
I am trying to build my WebGL dart application with "pub build".
I am able to run "pub serve" without problems, but "pub build" gives me 2 erros:
Directive not allowed here
part of MyProject
^^^^^^^^^^^^^^^^
Could not find main [I think this happends because of unfinished compile]
I only use browser:any as dependency.
Why could this be?
Thank you very much!
EDIT:
My pubspec.yaml
name: LD29
description: My LD29 game
author: snip
homepage: snip
dependencies:
browser: any
The includes:
library LD29;
import 'dart:html';
import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'dart:web_gl';
part 'Scene.dart';
part 'MainScene.dart';
part 'Entities.dart';
part 'Quadgrid.dart';
part 'Vecd.dart';
part 'Quad.dart';
part 'TexQuad.dart';
part 'ShaderProgram.dart';
part 'ShaderSource.dart';
part 'TextureGL.dart';
part 'FontRendering.dart';
The problematic "part of"
part of LD29;
class Quadgrid {
const static int size = 20;
const MAX_GRID_W = DISPLAY_WIDTH / size;
const MAX_GRID_H = DISPLAY_HEIGHT / size;
...
}
It seems no diffrent from my other files.
OK, after coming back to it a few months later, I gave debugging this problem another go. For my application, we moved the main() method to a different file than the one that had the 'library coUclient' command at the top. This meant that 'pub build' would fail:
master#dellaptop ~/Dropbox/Dart/coUclient $ pub build
Loading source assets...
Building coUclient...
[Info from Dart2JS]:
Compiling coUclient|web/dart/engine/initialize.dart...
[Error from Dart2JS]:
web/dart/engine/initialize.dart:1:1:
Directive not allowed here.
part of coUclient;
^^^^^^^^^^^^^^^^^^
[Warning from Dart2JS]:
web/dart/engine/initialize.dart:11:5:
Cannot resolve 'localStorage'.
if(localStorage["interface"] == null || localStorage["interface"] == "desktop")
^^^^^^^^^^^^
I don't know why I didn't see it before, but what tipped me off was that I saw it was starting the compile with initalize.dart and it occurred to me that that was the file that had main() in it. I then moved the main() method back into main.dart (which has the 'library coUclient' command at the top) and re-ran pub build. This time it succeeded because it started:
Loading source assets...
Building coUclient...
[Info from Dart2JS]:
Compiling coUclient|web/main.dart...
[Dart2JS on coUclient|web/main.dart]:
and all went well.
Moral of the story is, make sure your main() is in the same file as your 'library ' command and the "Directive not allowed here" problem shouldn't happen.
I'm boldly stepping into the world of AngularDart, admittedly not knowing too much Dart itself yet. I'm creating a new application that does nothing (yet), except includes the latest 'angular' package.
I'm using Dart 1.2.0 and AngularDart 0.9.9.
Very simple pubspec:
name: myapp
dependencies:
angular: any
My app layout:
pubspec.yaml
pubspec.lock
\lib
\packages
\web
In web I have a simple myapp.dart:
import 'package:angular/angular.dart';
main() {
}
My build seems to work fine, but I get the following warning:
Dart: Build
[Warning from Dart2JS on myapp|web/myapp.dart]:
packages\angular\angular.dart:31:23: Hint: Can't find 'animate' in the library 'angular'.
Is 'animate' spelled right?
#MirrorsUsed(targets: const [
^^^^^^^^
My question is, what does this mean, and is this anything to be concerned about?
This was a bug in AngularDart 0.9.9 and is fixed in current versions.
I searched for but didn't find any other posts remotely related to my question. Essentially, I'm attempting to follow the Dart Codelab from Google IO 2013 which I found here: http://goo.gl/4E21M
I'm attempting to use the Dart plugin in Webstorm 6 which I setup using the directions here: http://blog.jetbrains.com/webide/2012/12/dart-support-in-webstorm-6/
Lastly, I'm doing this on Windows 8.
My build.dart is:
import 'package:web_ui/component_build.dart';
import 'dart:io';
import 'dart:async';
void main() {
var args = new List.from(new Options().arguments);
build(new Options().arguments, ['web/index.html'])
.then((_) => print('Build finished!'));
}
My pubspec.yaml is:
name: writer
version: 0.0.1
author: Dart Team <misc#dartlang.org>
description: This is the finished version of the application built in the Google I/O 2013 Dart Codelab.
homepage: https://github.com/dart-lang/io-2013-dart-codelab
dependencies:
intl: any
web_ui: any
Yet, when I attempt to run the step 1 code, I see in my Event Log: Error running Test: build.dart: Missing library statement in build.dart.
So that seems straight-forward enough...except I can't figure out which library statement should be there that isn't... the only line of code I removed was:
#!/usr/bin/env dart
Because I'm attempting to run this on Windows, and that is for a UNIX environment.
Any thoughts? I really appreciate any assistance you can provide getting up and running with this Codelab in Webstorm (which is LIGHT YEARS more refined then the default Dart Editor). In other words, I FAR prefer Webstorm--if I can get things up and running in it.
Thank you in advance!
Thanks to #ChrisBuckett and #PixelElephant my question was answered. In order to get the Codelab from Google IO 2013, Step 1, to run I had to include "library build;" at the top of my build.dart file. In order to see the post-build output, I had to look in the /out folder and "run" the index.html file in Chromium.
This combination worked.
My fixed build.dart file:
library build;
import 'package:web_ui/component_build.dart';
import 'dart:io';
import 'dart:async';
void main() {
var args = new List.from(new Options().arguments);
build(args, ['web/index.html'])
.then((_) => print('Build finished!'));
}