close
Failed to precompile build_runner:build_runner Error, failed to precompile build_runner:build_runner error precompile build_runner:build_runner error on flutter, build_runner:build_runner error on flutter pub, failed to precompile build_runner:build_runner

[Solved] Failed to precompile build_runner:build_runner Error on flutter pub

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. Failed to precompile build_runner:build_runner in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Failed to precompile build_runner:build_runner Error on flutter pub ?

When I run flutter pub run build_runner build I am facing this issue. I have already tried

  1. First of all run flutter clean
  2. flutter pub-cache repair
  3. flutter pub get

build_runner are added on pubspec and flutter pub get ran successfully as well.

Failed to precompile build_runner:build_runner:
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:1600:40: Error: Getter not found: 'topLevelVariable'.
      return kinds.contains(TargetKind.topLevelVariable);
                                       ^^^^^^^^^^^^^^^^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Getter not found: 'topLevelVariable'.
      case TargetKind.topLevelVariable:
                      ^^^^^^^^^^^^^^^^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Type 'dynamic' of the case expression is not a subtype of type 'TargetKind' of this switch expression.
 - 'TargetKind' is from 'package:meta/meta_meta.dart' ('../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/meta_meta.dart').
      case TargetKind.topLevelVariable:
                      ^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2001:13: Context: The switch expression is here.
    switch (this) {
            ^
pub finished with exit code 1

How to Solve Failed to precompile build_runner:build_runner Error on flutter pub ?

  1. How to Solve Failed to precompile build_runner:build_runner Error on flutter pub ?

    To solve Failed to precompile build_runner:build_runner Error on flutter error The problem is in the analyzer plugin. When I add the analyzer dependency 1.5.0 in the dev-dependencies of pubspec.yaml worked for me. Just open your pubspec.yaml file. in the dev_dependencies just add analyzer dependency 1.5.0. Same as below.

  2. Failed to precompile build_runner:build_runner

    To solve Failed to precompile build_runner:build_runner Error on flutter error The problem is in the analyzer plugin. When I add the analyzer dependency 1.5.0 in the dev-dependencies of pubspec.yaml worked for me. Just open your pubspec.yaml file. in the dev_dependencies just add analyzer dependency 1.5.0. Same as below.

Solution 1

The problem is in the analyzer plugin. When I add the analyser dependency 1.5.0 in the dev-dependencies of pubspec.yaml worked for me.

  1. Just open your pubspec.yaml file.
  2. in the dev_dependencies just add analyzer dependency 1.5.0.
  3. Same as below.
 dev_dependencies:
   analyzer: 1.5.0

Solution 2

Another solution is Changing the analyzer version in pubspec.lock file to 1.5.0 seems to fix the issue.

Before

analyzer:
dependency: transitive
description:
  name: analyzer
  url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"

After

analyzer:
dependency: transitive
description:
  name: analyzer
  url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"

Then Just Run flutter clean and the flutter pub get.

Solution 3

I Think analyzer Plugins latest version seems to be an issue. just downgrade analyzer by version from 1.6.0 to 1.5.0.

Summery

So, It’s All About this error. I hope this tutorial helps you to solve your error. Please Comment Below if You stucks anywhere with my code.

Also Check Out Below Tutorials


Posted

in

by

Comments

Leave a Reply

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