too many imports cause `pub serve` to hang

Issue

When I run pub -v serve web for my AngularDart app, pub always hangs here:

% pub -v serve web
FINE: Pub 1.25.0-dev.16.4
FINE: Loading asset environment...
FINE: Initializing barback...
FINE: Serving packages on localhost:0.
MSG : Loading source assets...
FINE: Providing sources for ordreset|lib.
FINE: Loading source assets finished (0.053s).
FINE: Provided sources.
FINE: Loading transformers...
FINE: Transformer dependencies:
    | angular: -
    | test/pub_serve: -
    | dart_to_js_script_rewriter: -
FINE: Using cached transformer snapshot.
MSG : Loading angular, test/pub_serve and dart_to_js_script_rewriter transformers...
FINE: Loading transformers from [angular, test/pub_serve, dart_to_js_script_rewriter]
FINE: Spawning isolate from ./.pub/transformers/transformers.snapshot.
FINE: Loading angular, test/pub_serve and dart_to_js_script_rewriter transformers finished (0.151s).
FINE: Transformers from angular: {group of [[BuilderTransformer: Instance of 'TemplatePlaceholderBuilder'], [ReflectionRemover], [StylesheetCompiler, BuilderTransformer: Instance of 'LibraryBuilder']]}
FINE: Transformers from test/pub_serve: {PubServe}
FINE: Transformers from dart_to_js_script_rewriter: {DartToJsScriptRewriter}
FINE: Loading transformers finished (0.649s).
FINE: Initializing barback finished (0.763s).
FINE: Loading asset environment finished (1.062s).
FINE: Providing sources for ordreset|web.
FINE: Bound "web" to localhost:8080.
MSG : Serving ordreset web on http://localhost:8080
FINE: [Fine from StylesheetCompiler]:
    | [processStylesheet] took 50 ms on ordreset|lib/src/dashboard_component.css
FINE: [Fine from StylesheetCompiler on ordreset|lib/src/dashboard_component.css]:
    | Took 0.2s (0.0s awaiting secondary inputs).
FINE: [Fine from StylesheetCompiler]:
    | [processStylesheet] took 30 ms on ordreset|web/main.css
FINE: [Fine from StylesheetCompiler on ordreset|web/main.css]:
    | Took 0.2s (0.0s awaiting secondary inputs).
FINE: [Fine from BuilderTransformer: Instance of 'TemplatePlaceholderBuilder' on ordreset|primary]:
    | Took 0.4s (0.0s awaiting secondary inputs).
FINE: [Fine from BuilderTransformer: Instance of 'LibraryBuilder' on ordreset|primary]:
    | Not yet complete after 10.0s
FINE: [Fine from BuilderTransformer: Instance of 'LibraryBuilder' on ordreset|primary]:
    | Not yet complete after 20.0s

I noticed that when removing all import 'package:xml/xml.dart' as xml; statements, that pub serve doesn’t hang anymore then. But I did observe the same behaviour in the past, that removing all import 'package:angular_components/angular_components.dart'; fixed the problem as well. Hence I actually doubt that it’s a problem with either the xml or the angular_components package but that the problem might be related to an import limitation of source_gen, similar to this issue from the past.

I’ve uploaded my AngularDart project here. You can run pub get and then pub -v serve web yourself to see how pub hangs.

PS: I’ve emptied all AngularDart HTML template files before pushing the code to the public GitHub repo for privacy reasons but that shouldn’t change the fact that pub serve should still succeed.

Solution

As @GünterZöchbauer pointed out in a comment of his answer, following the steps below solves the problem:

  1. Remove .pub in your project folder.
  2. Run pub get --no-precompile instead of a regular pub get to prevent precompiling which seems to cause the problem.
  3. Now run pub serve as usual.

Answered By – ben4ever

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *