"JavaScript Debug Configuration" debug launch for Dart project results in pub error "Directory "lib" is not allowed."

I have a Dart project that I am attempting to launch in Debug mode from Webstorm.  To do so I have right clicked on my "index.html" and selected Debug. This automatically created a JavaScript Debug Configuration entry in the Configurations settings area.  However, whenever I click Debug for this configuration (including the first time) the browser launches but the program does not run.  The following error message is found in the "Pub Serve" tray panel:

/usr/lib/dart/bin/pub serve web --port=57607
Loading source assets...
Loading dart_to_js_script_rewriter transformers...
Serving plinypad web on http://localhost:57607
Build completed successfully
[web] GET Served 5 assets.
/usr/lib/dart/bin/pub serve lib --port=54722
[web] GET Served 14 assets.
Directory "lib" is not allowed.

Usage: pub serve [directories...]
-h, --help Print this usage information.
--mode Mode to run transformers in.
(defaults to "debug")

--all Use all default source directories.
-D, --define Defines an environment constant for dart2js.
--hostname The hostname to listen on.
(defaults to "localhost")

--port The base port to listen on.
(defaults to "8080")

--[no-]dart2js Compile Dart to JavaScript.
(defaults to on)

--[no-]force-poll Force the use of a polling filesystem watcher.

Run "pub help" to see global options.
See http://dartlang.org/tools/pub/cmd/pub-serve.html for detailed documentation.
Pub Serve terminated

I have other Dart projects on the same machine that appear to work fine, however, when they launch I see the following output with only one invocation of pub

/usr/lib/dart/bin/pub serve web --port=58172

Loading source assets...

Loading dart_to_js_script_rewriter transformers...
Serving vellum web on http://localhost:58172
Build completed successfully
[web] GET Served 5 assets.
[web] GET Served 272 assets.

6 comments
Comment actions Permalink

I've discovered the issue come ups when I change my content root. If I start a new default project and run the default simple web app the program launches fine and only has 

/usr/lib/dart/bin/pub serve web --port=38059

displayed in Pub Serve.

As soon as I change the content root to point to my existing application the problem begins to arise with both the line above and

/usr/lib/dart/bin/pub serve lib --port=54943

0
Comment actions Permalink

Most likely your project violates Pub Package Layout Conventions

I guess you have some *.dart file in web folder that references another *.dart file from lib folder by relative path (this may be an import, export or part statement). This doesn't work in dart. Make sure that:

  • for each main library file - all of its parts are withing the same root dir (for example all in lib or all in web)
  • there are no references from files in lib folder to files that are outside of lib
  • files outside of lib (e.g. in web) may reference files in lib only using URI like package:ProjectName/fileInLib.dart
  • starting points are not allowed in lib folder: you shouldn't have *.html files and *.dart files with main() method there

When you fix all of these, you should not see 'pub serve lib' any more.

1
Comment actions Permalink

This was the problem.  Thanks.

0
Comment actions Permalink

Alexander,

What about files in the /packages folder referenced within /lib/main_app.dart of a sample Polymer Dart project as in:

@HtmlImport('main_app.html')
library proactive_healthcare.lib.main_app;

import 'dart:html';

import 'package:polymer_elements/paper_input.dart';
import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart';

/// Uses [PaperInput]
@PolymerRegister('main-app')
class MainApp extends PolymerElement {
@property
String text;

/// Constructor used to create instance of MainApp.
MainApp.created() : super.created();

@reflectable
String reverseText(String text) {
return text.split('').reversed.join('');
}
}

Do the three import statements in the header go against the rule of the second bullet item? Thanks.

 

0
Comment actions Permalink

Let me clarify the 2nd bullet:

  • there are no references from files in lib folder to files in the same Dart package that are outside of lib

References to other packages are allowed in any file.

0
Comment actions Permalink

Thanks for the clarification.

0

Please sign in to leave a comment.