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

Cannot find package when running file in subdirectory. #16947

Closed
DartBot opened this issue Feb 19, 2014 · 10 comments
Closed

Cannot find package when running file in subdirectory. #16947

DartBot opened this issue Feb 19, 2014 · 10 comments
Assignees
Labels
closed-as-intended Closed as the reported issue is expected behavior
Milestone

Comments

@DartBot
Copy link

DartBot commented Feb 19, 2014

This issue was originally filed by @zoechi


What steps will reproduce the problem?
1.
I have this Dart script
mypackage/bin/list_equality/main.dart

with the content
library x;

import 'package:collection/equality.dart';

void main(List<String> args) {
  if (const IterableEquality().equals([1,2,3],[1,2,3])) {
      print("Equal");
  } else {
      print("Not equal");
  }
}

2.
When I run it I get
Unable to open file: /home/myuser/dart/playground/bin/list_equality/packages/collection/equality.dart'file:///home/myuser/dart/playground/bin/list_equality/main.dart': error: line 3 pos 1: library handler failed
import 'package:collection/equality.dart';
3.

When I move main.dart one level higher (out of 'list_equality' it works.
"import 'dart:xxx'" works in this sub directory but the 'package:collection/equality.dart' doesn't.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
Dart VM version: 1.2.0-dev.5.10 (Wed Feb 19 01:25:31 2014) on "linux_x64"

Please provide any additional information below.

@lrhn
Copy link
Member

lrhn commented Feb 20, 2014

It seems you are running with "home/myuser/dart/playground/bin/list_equality/packages" as the package directory. It is probably chosen as the default because you haven't specified a package-root.

Are you running this from the editor?

Can you pass an explicit package root to the VM:
  dart --package-root=/home/myuser/dart/playground/bin/packages mypackage/bin/list_equality/main.dart
?


Added Area-Editor, NeedsInfo labels.
Changed the title to: "Cannot find package when running file in subdirectory.".

@DartBot
Copy link
Author

DartBot commented Feb 20, 2014

This comment was originally written by @zoechi


Your are right, when I run it from command line with --packages-root it works

dart --package-root=packages bin/list_equality/main.dart # works
dart bin/list_equality/main.dart #fails, I expected this to work
I understand that
main.dart #from within bin/list_equality may not work

From Darteditor context menu 'run' fails
A launch configuration would probably help?
I expected this to work without though, shouldn't is?

@clayberg
Copy link

Set owner to @keertip.
Added this to the 1.3 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium, Triaged labels.

@keertip
Copy link
Contributor

keertip commented Feb 20, 2014

@gzoechi,

To specify package root in the editor, context menu for project in the Files View > Properties > Dart > Package Root settings. Once you set that, the launch will pick it up and it should run fine. The default is to look in the project for a packages directory.

@DartBot
Copy link
Author

DartBot commented Feb 20, 2014

This comment was originally written by @zoechi


@kertip

I'm not convinced that this is a solution.

I have the default packages directory, why should I change the configuration then.

I think I just want to know if it is an out of the box supported scenario to have a script file in a subdirectory of bin.
I thought this should work out of the box - in this case it is a bug that it doesn't work.

If you say only the bin directory itself is supported without special settings, it's fine too, then you can simply close this issue.

I'm glad I asked anyway because I again learned a few new things.
Thanks!

@DartBot
Copy link
Author

DartBot commented Feb 22, 2014

This comment was originally written by @zoechi


Now I have this problem with a unit test.

It seems the cause is that I moved the subdirectory from

test/db/di to
test/di

which broke the packages symlink

the directory list_equality (above) has no packages symlink at all (I thought they are gone already. It was mentioned frequently that a solution without symlinks is WIP)

I'm still not sure how to cope with such situations.
When are the packages symlinks created and from what tool (pub, Darteditor, ...)?
Should they get updated when they are broken, or does this only work when the directory was moved from Darteditor?
(I do it manually most of the time because Darteditor refuses to do it (a message like 'Directory out of sync' or similar messages is all I get when I try it with DartEditor)
How can this be initiated when it's not done automatically (by tools, I can of course fix symlinks manually)?

@keertip
Copy link
Contributor

keertip commented Mar 18, 2014

The packages symlinks are created by pub and not DartEditor. It creates a packages fodler in web and test and all its subfolders, and in bin. You can run pub get to create the symlinks when you create new folders. DartEditor tries to do this automatically, but am sure there are missed cases.

If you move/create directories, do run pub get.

Closing this issue, reopen if necessary.


Added AsDesigned label.

@DartBot
Copy link
Author

DartBot commented Mar 19, 2014

This comment was originally written by @zoechi


Thanks for the info. I never saw this mentioned before, that pub get creates the symlinks. Can you please verify that this is documented somewhere.
Maybe you don't want to document it because you try to get rid of symlinks anyway. I'm fine with that too. I have all the information I need.

@DartBot
Copy link
Author

DartBot commented Jun 1, 2014

This comment was originally written by @zoechi


I have a dart file in mypackage/bin/async/delay and pub get doesn't create a symlink for packages.
See also http://stackoverflow.com/questions/23975460

@DartBot
Copy link
Author

DartBot commented Oct 11, 2014

This comment was originally written by @zoechi


Seems also not to work for others in subdirectories of bin http://stackoverflow.com/questions/26313199

@DartBot DartBot added Type-Defect closed-as-intended Closed as the reported issue is expected behavior labels Oct 11, 2014
@DartBot DartBot added this to the 1.3 milestone Oct 11, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

4 participants