4

I have this pubspec.yaml

    name: Dart Pages
    description: The Dart platform.
    dependencies:
      web_components: any
      mongo_dart: any

then I run Tools > Pub Install, the operation completes successfully.

When I run the application I get the following error:

    dart --enable-checked-mode web\page.dart
    Unable to open file: C:/Users/Samer/Documents/GitHub/dart/web/packages/mongo_dart/mongo_dart.dart'file:///C:/Users/Samer/Documents/GitHub/dart/web/page.dart': Error: line 1 pos 1: library handler failed
    #import("package:mongo_dart/mongo_dart.dart");

I'm using Windows 7 64bit & Latest Dart Editor version 0.2.1_r14167

The issues seems not be with only mongo_dart, but all other libraries as well, the editor is looking for the wrong path over packages at /dart/web/packages, while i see a in folder /dart/packages.

Thank you for your help and time.

Adinia
  • 3,722
  • 5
  • 40
  • 58
samer.ali
  • 396
  • 2
  • 3
  • 11
  • Can you please post a description of your file layout? Can you confirm if the web directory got a symlink to packages directory? Can you paste in the code for page.dart? Thanks! – Seth Ladd Oct 31 '12 at 21:07

5 Answers5

1

Have you run pub install since you created the "web" directory? If not, try that. You need to have a "packages" directory inside the directory that contains your Dart entrypoint in order for "package:" imports to resolve correctly.

Pub will create those directories for you, but it needs to know to do that. If you add a new directory to your package, you'll want to run pub install again so it add a "packages" directory to it.

munificent
  • 11,946
  • 2
  • 38
  • 55
1

I had a similar problem with TeamCity. On my development machine I can do pub get and pub build over and over and it works just great, but this only worked the very first time I built the solution using TeamCity.

After a lot of messing around I finally discovered, mostly by trial and error, that the problem was caused by TeamCity cleaning the folder before building the solution.

I can't find any reasonable documentation for how pub works, and I don't know why this only works the very first time, but my trial and error discovered that executing pub cache repair on every build before pub get and finally pub build works repeatably, and my TeamCity project now builds successfully every time.

bikeman868
  • 2,236
  • 23
  • 30
  • That sounds cumbersome. I don't know TeamCity. Is it possible it runs several `pub get` concurrently? Maybe there is a way to specify the pub-cache directory to use to use a different one for each instance (have to look it up, not on my computer yet) – Günter Zöchbauer Sep 17 '15 at 04:16
  • It is possible to configure TeamCity to start a new build even when the current build is still running, but this is _not_ the default setting. It is also possible to get TeamCity to always use the same folder for a particular build, and not clear the contents between builds; which solves this problem but it's not a clean build. I like to know that if I get my solution from source control that it will build into an empty folder. – bikeman868 Dec 05 '15 at 00:56
0

I had something similar here, with the js-interop package. I changed the ':' to '/' and it worked.

Original declaration:

    import("package:mongo_dart/mongo_dart.dart");

Modified declaration:

    #import("package/mongo_dart/mongo_dart.dart");

You could also try this (It has worked to me):

    import 'packages/mongo_dart/mongo_dart.dart';
Eduardo Copat
  • 4,941
  • 5
  • 23
  • 40
  • 1
    This may work sometimes, coincidentally, but you really don't want to do this. Doing so will break transitive imports. If A imports B which imports C using the above syntax, it's unlikely to resolve correctly. – munificent Nov 01 '12 at 17:16
0

You might need to add an additional library where you import mongo_dart.dart and then import the library in your main. It's a weird solution I know but it worked for me when I was trying to get Google Maps running inside Dart.

More here: https://groups.google.com/a/dartlang.org/d/msg/misc/ORXJmmmH3fA/WIKyBik1e7sJ

Stan
  • 1,251
  • 1
  • 15
  • 24
0

I was having similar problems trying to import unittest. I'm running Eclipse 4.2 in windows 7 64 bit with the dart editor plugin.

Deleting the 'pub' folder under c:\USERS\<user>\AppData\Roaming\ worked for me.

The credit goes to Samer Ali on the darlang google group for this one, see here.

poida
  • 3,403
  • 26
  • 26