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.
Related
I'm running pub get and its reporting that it can't find a pubspec.yaml file in unittest package, anyone seen this before? Im on Dart Editor version 1.8.0.dev_00_00 (DEV) Dart SDK version 1.8.0-dev.0.0
The downloaded package in
C:\Users\daniel\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\unittest-0.11.0+5
didn't have a pubspec.yaml file in it, and using pub cache repair wouldn't work for that very reason also so I had to manually open the directory and delete it then when I did a new pub get it did work. Sounds like cache repair might need tweaking to make it delete any corrupted packages that didnt have their pubspecs downloaded with them and I beleive this broken state was created by me running a pub get whislt a pub get was already in progress on the same pubspec.yaml file, so probably best you avoid doing that.
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.
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.
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.
Running pub update ...
Pub update failed, [1] Resolving dependencies...
DirectoryIOException: Directory listing failed, path = <longpath>/web/css/packages (OS Error: No such file or directory, errno = 2)
Why would pub suddenly try to look for packages in my css folder?
The short answer, pub puts symlinks into subdirectories to ensure that you can use package: in any Dart file in any subdirectory of a "deployable" directory.
Because web is deployable in the sense that you'll likely take everything in web and throw it up on a web server, pub wants to make it easy for Dart files to work.
There are no conventions right now, so pub takes the optimistic approach because it can't anticipate where you might put Dart files.
Regardless, you shouldn't get an error, so this might be a bug. I just tried it on a brand new sample app with a web/css and pub install and pub update worked for me.
Can you please submit a bug at http://dartbug.com/new with details of your OS and the output of dart --version ? Many thanks!