dartanalyzer and packages resolution

61 views
Skip to first unread message

Michael Haubenwallner

unread,
Oct 24, 2014, 8:13:21 AM10/24/14
to mi...@dartlang.org
I have this ugly problem with Sublime Text for Dart. Package imports are not resolved in dart files.
That is, dartanalyzer complains like 'Could not resolve URI (package:.../...) ..:'.

The same error is produced in the console, if dartanalyzer is not run from the project root folder.
DART_SDK packages are resolved though. Sym-links for 'packages' exist in all relevant folders.


I haven't found other people reporting this problem, maybe it is just a PATH or pub-cache related issue?

Brian Wilkerson

unread,
Oct 24, 2014, 10:58:10 AM10/24/14
to General Dart Discussion
Michael,

The command-line analyzer can resolve package: URI's in one of two ways. Either you can provide a --package-root argument on the command line giving it the path to the packages directory, or it can be run from the directory containing the pubspec.yaml file.

The difficulty for Sublime, of course, is that the file being edited won't always be in the same directory as the pubspec. One solution would be for the Sublime plugin to look at the file's path and find the most deeply nested directory that contains a packages directory. It could then pass the path to the packages directory in as the value of the --package-root argument.

Brian

Matthew Butler

unread,
Oct 24, 2014, 11:04:39 AM10/24/14
to mi...@dartlang.org


On Friday, October 24, 2014 11:58:10 AM UTC-3, Brian Wilkerson wrote:

The difficulty for Sublime, of course, is that the file being edited won't always be in the same directory as the pubspec. One solution would be for the Sublime plugin to look at the file's path and find the most deeply nested directory that contains a packages directory. It could then pass the path to the packages directory in as the value of the --package-root argument.

I don't follow, isn't that why the packages/ directory is created in each sub folder (except lib)? 

Brian

Matt 

Brian Wilkerson

unread,
Oct 24, 2014, 11:16:15 AM10/24/14
to General Dart Discussion
Matt,

I don't follow, isn't that why the packages/ directory is created in each sub folder (except lib)?

First, to the best of my knowledge, pub only creates a packages directory in each sub folder under Windows. I know that it does not do so for me when I'm running on my Mac and using Dart Editor to run pub for me.

Second, I omitted a small detail because I didn't think it was relevant. If there is no --package-root argument, analyzer will run pub in the current directory asking for a package map (a table mapping package names to the root directory used to resolve package: URI's for that package). Pub needs to be run from the directory containing the pubspec. Hence, dartanalyzer needs to be run from the directory containing the pubspec unless you explicitly provide a package root.

Brian

Günter Zöchbauer

unread,
Oct 24, 2014, 11:16:26 AM10/24/14
to mi...@dartlang.org
Maybe the problem is, that they aren't created ;-) 

Brian

Matt 

Matthew Butler

unread,
Oct 24, 2014, 11:58:10 AM10/24/14
to mi...@dartlang.org


On Friday, October 24, 2014 12:16:15 PM UTC-3, Brian Wilkerson wrote:
Matt,

I don't follow, isn't that why the packages/ directory is created in each sub folder (except lib)?

First, to the best of my knowledge, pub only creates a packages directory in each sub folder under Windows. I know that it does not do so for me when I'm running on my Mac and using Dart Editor to run pub for me.

I'm not sure on Mac, but they are created in Linux but they're simply not displayed in the Dart Editor. (ls -l shows them from the test directory on my package in linux for exmaple). 

Second, I omitted a small detail because I didn't think it was relevant. If there is no --package-root argument, analyzer will run pub in the current directory asking for a package map (a table mapping package names to the root directory used to resolve package: URI's for that package). Pub needs to be run from the directory containing the pubspec. Hence, dartanalyzer needs to be run from the directory containing the pubspec unless you explicitly provide a package root.

I think it may be more of the second instance here, that dartanalyzer is trying to run pub from the subdirectory, even with the packages directory present. 

Brian

Thanks,
Matt 

Alexander Doroshko

unread,
Oct 24, 2014, 12:05:06 PM10/24/14
to mi...@dartlang.org
On 24.10.2014 19:58, Matthew Butler wrote:


On Friday, October 24, 2014 12:16:15 PM UTC-3, Brian Wilkerson wrote:
Matt,

I don't follow, isn't that why the packages/ directory is created in each sub folder (except lib)?

First, to the best of my knowledge, pub only creates a packages directory in each sub folder under Windows. I know that it does not do so for me when I'm running on my Mac and using Dart Editor to run pub for me.

I'm not sure on Mac, but they are created in Linux but they're simply not displayed in the Dart Editor. (ls -l shows them from the test directory on my package in linux for exmaple).

It is there on Mac as well in each subfolder, DartEditor simply hides these symlinks.

Brian Wilkerson

unread,
Oct 24, 2014, 12:14:24 PM10/24/14
to General Dart Discussion
Alexander,

It is there on Mac as well in each subfolder, DartEditor simply hides these symlinks.

Actually, I was using Finder to look for them, and they're not there. At least not where I was looking in 'lib'. They are there in 'bin' and 'test', and there are a couple of other directories where they show up. But if you're editing a file somewhere inside 'lib' there won't be a 'packages' directory next to the file.

Brian

Alexander Doroshko

unread,
Oct 24, 2014, 12:19:17 PM10/24/14
to mi...@dartlang.org
That's the same for all OSes. According to the spec [1] copies of the main 'packages' folder are created:
- in the 'bin' folder (but not in its subfolders)
- in 'benchmark', 'bin', 'example', 'test', 'tool', and 'web' and all their subfolders recursively

[1] https://www.dartlang.org/tools/pub/glossary.html#entrypoint-directory

Matthew Butler

unread,
Oct 24, 2014, 12:20:51 PM10/24/14
to mi...@dartlang.org
Agreed, In order to prevent recursive symlinks, pub does not create a packages folder for files in the lib/ folder. Other folders like test (the one in question), bin, web etc will have these. But as you mentioned the analyzer running pub regardless of the packages folder makes it a moot point anyways. Thanks again on that info. :)
 
Brian

Matt 

Alexander Doroshko

unread,
Oct 24, 2014, 12:25:58 PM10/24/14
to mi...@dartlang.org
Sorry for the typo (listed 'bin' twice). Correct is:


That's the same for all OSes. According to the spec [1] copies of the main 'packages' folder are created:
- in the 'bin' folder (but not in its subfolders)
- in 'benchmark', 'example', 'test', 'tool', and 'web' and all their subfolders recursively

[1] https://www.dartlang.org/tools/pub/glossary.html#entrypoint-directory
 

Michael Haubenwallner

unread,
Oct 25, 2014, 6:50:16 AM10/25/14
to mi...@dartlang.org
Problem fixed in https://github.com/guillermooo/dart-sublime-bundle Release 1.1.1
     - Run analyzer from pubspec.yaml's dir
Reply all
Reply to author
Forward
0 new messages