DART: Run pub build on library fails with "[65] There are no source directories present"

167 views Asked by At

In my first Dart (command line) application I use 3 classes. Initially they all were in the same source file. All worked fine. Then I decided to move one class into a newly created library. I created a new project of type "Package Template" and put the class file with an added library tag line at the top into the 'lib' folder (as seen with other library packages and described in the pub file structure conventions).

To be able to use the library class I understood that I had to "Run pub build" from the yaml file of the library package first. When I do that I get the error message:

Pub build failed, [65] There are no source directories present. The default directories are "benchmark", "bin", "example", "test" and "web".

My source file is in the 'lib' directory. I have seen this to be the case with all installed packages and it is described this way in the pub documentation. I have no idea what I miss here. Any hint is appreciated.

1

There are 1 answers

1
Günter Zöchbauer On BEST ANSWER

You don't need to run pub build to be able to use a library. You need pub build to generate JavaScript from Dart for a browser application.

Your question doesn't contain much information about your package directory layout or contents of your files but - the file containing main() needs to be in one of the directories listed in the error message - the file containing main() needs an import statement import 'package:your_package/your_lib_file.dart'; so you can launch your app and using the library from the lib directory of your package.