Dart2JS Cannot Find Import Packages WebStorm - dart

I am using the WebStorm 8 IDE to build a dart web app. I have the following directory structure:
root
web
main.dart
lib
packages
browser
intl
intl.dart
pubspec.lock
pubspec.yaml
In main.dart I have the following import statment: import "package:intl/intl.dart";
However when I try and compile main.dart to javascript I get the following error:
dart2js
Error occurred:
/Path/To/Project/root/web/main.dart:2:8:
Error: Can't read 'package:intl/intl.dart' (Error reading '/Path/To/Project/root/web/packages/intl/intl.dart' (OS Error: No such file or directory, errno = 2)).
import "package:../packages/intl/intl.dart";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Compilation failed.
So it seems that dart2js looks in the current directory of the dart file to be converted for the packages, which is incorrect.
I tried changing my import statement to import "package:../packages/intl/intl.dart"; but I got the same error.
Does anyone have any ideas?
UPDATE:
I can use pub build to build my project and produce a main.dart.js. Not sure what is different when I call build, perhaps something is wrong with WebStorm?

dart2js is not a recommended workflow and can be buggy in WebStorm 8. It is completely removed from the context menu in the upcoming WebStorm 9. Use 'pub build'.

I can't see anything wrong. I think this is one of the cases where only
pub cache repair
can help.

Related

Dart web application can not import local package

I have developed a simple library (called picasawebalbums) that I wish to import in another web application.
I have added the the following to pubspect.yaml
picasawebalbums:
path: C:\Users\hangs_000\Documents\GitHub\PicasaWebAlbums
But the package does not appear under the 'packages' directory and of course my dart code cannot import any of the classes.
I feel that I have missed out a step somewhere.
Try pub get --verbose or pub upgrade --verbose from command line in your application directory and look at the output. You can try without --verbose first. This prints much less but may offer a hint anywhere.

fileSystem.chooseEntry from package:chrome/app.dart generates runtime error

Has anyone successfully used any fileSystem calls in package:chrome/app.dart? (This is the Chrome API package for Google Dart.)
Here's my code:
import 'package:chrome/app.dart';
void main() {
fileSystem.chooseEntry();
}
Here's my pubspec.yaml file:
name: ChooseEntry
description: A sample chrome packaged application
dependencies:
browser: any
chrome: any
meta: any
The other files were generated automatically by the Dart Editor and remain untouched by me.
The error I get from Dartium is:
Breaking on exception: 'package:chrome/src/common.dart': malformed type: line 72 pos 29: type 'js.Callback' is not loaded
When I compile to JS and run in Dartium or Chrome, I get this error:
Uncaught RuntimeError: Error: Cannot resolve 'Callback'.
So, my question is whether anyone has successfully used the chooseEntry API, or any API in fileSystem and, if so, what about what I did needs to be fixed. My guess is that I'm missing a package, but I can't identify what it might be.
I did add package "js" to pubspec.yaml, with no effect. I also tried making copies of all the packages, in case Dartium or Chrome didn't handle the symlinks correctly, and that didn't help either. (I doubt that that's the problem, as it found the code for fileSystem.chooseEntry just fine.)
I'm using:
Dart Editor version 1.0.0_r30798 (STABLE)
Dart SDK version 1.0.0.10_r30798
The chrome package appears not to be maintained anymore, consider using chrome_gen instead by replacing chrome with chrome_gen in pubspec.yaml and by editing the import statement like this:
import 'package:chrome_gen/chrome_app.dart';
main() {
fileSystem.chooseEntry();
}
The difference between these two packages is that wrappers are hand-written in chrome and autogenerated in chrome_gen from the json and idl files from Chrome.
Links:
Pub Package: chrome_gen
Mailing List: What is the difference between chrome and chrome_gen ?

Failed to load package in Dart

When I try to import a package with the syntax import 'package:markdown/markdown.dart';, I get no error in Dart Editor but when I run the dart application, the debugger shows me the message:
An error occurred loading file: package:markdown/markdown.dart
Failed to load resource
chrome-extension://gfjabgeipkcfopofkhjimepepnomcidk/dart/packages/markdown/markdown.dart
But when I write the whole path (import "../../packages/markdown/markdown.dart";) everything works fine. I cannot understand why the syntax package: doesn't work in my code though it works in Dart Editor's own examples.
You can see the Chrome app architecture below (I'm loading a package from translator.dart):
You should have the package added as a dependency in pubspec.yaml (which I assume you do).
Also try running following:
delete packages folder
delete pubspec.lock
run pub get to fetch the
dependencies again.
I think in your md_to_html folder you need a link to the 'packages' directory for the shortform to work. I seem to remember this happening when the workspace is built but I'm not sure now which command triggers it, have a look at the current pub docs.

Pub does not download dependencies on Windows 7 after the update to lib v2 (SDK 0.3.1_r17328)

After the update to the version 0.3.1_r17328 of Dart SDK and Dart Editor I have some trouble to import some library particulary Args library. I have the same problem both directly importing Args or importing Web_ui where Args is one of the dependencies.
Here is my pubspec.yaml:
name: notes
description: A sample application
dependencies:
web_ui: 0.3.0+1
or:
name: notes
description: A sample application
dependencies:
args: 0.3.1+1
Here is the error generate from build.dart
Unable to open file: C:/Users/Fabio/Dropbox/progetti/note/packages/args/args.dart'package:web_ui/component_build.dart': Error: line 25 pos 1: library handler failed
import 'package:args/args.dart';
'file:///C:/Users/Fabio/Dropbox/progetti/note/build.dart': Error: line 1 pos 1: library handler failed
import 'package:web_ui/component_build.dart';
I solved the problem. It seems that the Cache folder (Pub) has been corrupted.
I have deleted the folder Cache: C:\Users\<UserName>\AppData\Roaming\Pub
Then i run pub install from command line and it works.
Unfortunately, I was getting the same error with my windows XP machine.
In the end, I logged into my windows 7 machine and was able to
download the packages, zipped them up and pasted the libraries into my
windows XP dart editor. Success!
I had no reason to believe I had the exact proxy issue #shindokaku had as I am using my home computer.
I tried all the suggestions on deleting the .cache files, pub.lock files and the packages folder and retrying. I uninstalled dart editor and tried again. I also tried using the git resources to download web-ui and running commands through the command line to no avail
Including suggestions in this similar questions:
cannot-find-referenced-source-packages
is-there-a-workaround-for-pub-dependency-resolution-through-proxies
This problem has been haunting me over and over for a few weeks. I am not using Windows, so this answer is not intended to help the original poster who is using Windows 7.
If you are using Linux here are the steps I use to repair corrupted pub cache.
Go to the top level directory of your app. You should see at least pubspec.lock, pubspec.yaml, a folder named packages, and a folder named web.
Delete your pubspec.lock, and packages folder.
[Make sure you aren't storing your own libraries in the packages folder]
cd ~/dart/myApp/
rm -r packages
rm pubspec.lock
Now once you have removed these files:
pub cache repair
Note 1: if your dart-sdk is not in your systems $PATH, than you will want to use the absolute path to the sdk when using the above command. Comment if you need that explained.
Note 2: This is working solution with Dart 1.5.3. I have not tested this on earlier versions.
Try deleting your pubspec.lock file and packages directory in the root folder of the project. Then run pub install again, when things get wacky thats what I do.
You should try to run pub update. I have sometimes found that this doesn't work as expected from the editor, but generally works quite smoothly when called from the command line.

How do I compile a uxl-file from Dart-Editor?

I installed the dependencies from this tutorial http://docs.rikulo.org/rikulo/latest/UXL/Fundamentals/UXL_Overview.html
dependencies:
rikulo_uxl:
git: git://github.com/rikulo/uxl.git
trying to compile with uc.dart
I get:
Error: line 8 pos 1: library handler failed
import 'package:args/args.dart';
what is wrong? missing path?
This normally happens when you reference a package that isn't found on disk. You should ensure you have the package listed in your pubspec.yaml and that you've run pub get. You can also check that inside your packages folder you can see a folder named args.

Resources