Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find a file named "pubspec.yaml" when auto generating code with build_runner

Tags:

flutter

After I have updated Flutter to v1.22 using code generation with build_runner was not working. I was told that the proper command to use in this version was:

dart pub run build_runner watch --delete-conflicting outputs

However, I receive the following error:

Could not find a file named "pubspec.yaml" in "C:\Users\jpiab\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\_fe_analyzer_shared-2.2.0".

I have no idea why it is looking for pubspec.yaml in that folder, since that folder is not the current working directory.

--- EDIT ---

The file exists in path: C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-2.2.0

dart is just looking for it in the wrong place. Any ideas on how to fix it?

like image 638
João Abrantes Avatar asked Oct 06 '20 09:10

João Abrantes


People also ask

Where can I find Pubspec Yaml?

Every Flutter project includes a pubspec. yaml file, often referred to as the pubspec. A basic pubspec is generated when you create a new Flutter project. It's located at the top of the project tree and contains metadata about the project that the Dart and Flutter tooling needs to know.

What does Pubspec Yaml mean?

The pubspec. yaml file is transversal to all apps and packages - it is where we add metadata to our project, stipulate the Dart and Flutter SDK constraints, manage the dependencies and also set Flutter-specific configurations.

How do you add dependency in Pubspec Yaml in flutter?

You can go to the pubspec. yaml file and add dependencies ,under dependencies and then packages get will do the work. or you can run flutter pub get in the terminal.


2 Answers

I solved for me. I use Android Studio in Ubuntu 20.04.01 LTS.

Firstly run this command:

flutter pub get

After run this command:

flutter packages pub run build_runner build

Or:

flutter packages pub run build_runner watch

Source: https://github.com/flutter/flutter/issues/50092

like image 120
serkanayaz Avatar answered Sep 30 '22 20:09

serkanayaz


That same error I had and I resolved it by aligning my dependencies. Check if your build_runner is in the same line as flutter_test if you added it to dev_dependencies.

Error Corrected

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner: [latest]

My Error

dev_dependencies:
  flutter_test:
    sdk: flutter
    build_runner: [latest]
like image 32
Mathias Godwin Avatar answered Sep 30 '22 20:09

Mathias Godwin