73

I create a simple Web application but when I want to run it I got this message in "Tools Output":

Could not find a file named"pubspec.yaml"in"/home/reza/.pubcache/hosted/pub.dartlang.org/browser-0.10.0+2".

How can I fix this problem?

I use Ubuntu 14.04LTS 64bit and Dart Editor 1.7.2

TylerH
  • 20,799
  • 66
  • 75
  • 101
Reza
  • 996
  • 1
  • 9
  • 16
  • 2
    In my case, the reason for this problem was that I used to pull the packges using `flutter pub get`, but I ran build_runner with `dart run build_runner ...`. But `flutter` and `dart` use different working directories. So be sure to run build_runner with the same command as the one you pulled the packages with. – Stacky Jun 30 '22 at 13:16
  • The above was my problem too! Why not make an answer out of that? – Karolina Hagegård Oct 28 '22 at 17:12

28 Answers28

79

This has happened to me several times:

What's ultimately solved things for me (OS X) is deleting pub's cache:

sudo rm -Rf /Users/<username>/.pub-cache

Also, delete the packages directory in your project's root:

sudo rm -Rf .packages

Then pub get again in your project(s), but make sure that you are not operating as root (a whoami will tell you, and an exit will get you out of there).

Loïc Fonkam
  • 2,284
  • 11
  • 25
David Notik
  • 2,026
  • 15
  • 21
  • Thank you for this, had me stuffing around for half hour before I tried SO. Your solution worked. My packages folder was in `.packages` so I issued `sudo rm -Rf .packages` to remove it. – Dom Feb 21 '21 at 09:04
  • Thanks. I was getting Could not find a file named "pubspec.yaml" in ".pub-cache/hosted/pub.dartlang.org/devtools...". And after remove .pub-cache + pub get now is working fine. – speksy Jul 17 '21 at 15:14
  • 3
    On windows, I deleted the pubspec.lock file, after that I wrote to console flutter clean and flutter pub get. It works like this on windows – alperefesahin Oct 23 '21 at 16:42
  • I have this error with the first comand: 'sudo' is not recognized as an internal or external command, operable program or batch file. – Moises Conejo Oct 21 '22 at 15:21
56

I was facing a similar issue when running even a simple dart run:

Could not find a file named "pubspec.yaml" in '/Users/<username>/.pub-cache/hosted/pub.dartlang.org/animated_widgets-1.1.0'

So I managed to fix it by these steps:

  • sudo rm -Rf /Users/<username>/.pub-cache.
  • flutter clean in the current project folder.
  • MOST IMPORTANT run dart pub get
  • flutter pub get

And it finally worked

amatkivskiy
  • 1,154
  • 8
  • 11
  • 15
    Thank you, `dart pub get` did it for me – simodev Dec 02 '21 at 09:19
  • 1
    Didn't work, still get error: Could not find a file named "pubspec.yaml" in "/Library/Flutter/.pub-cache/hosted/pub.dartlang.org/device_info_plus-3.1.1". – Justin Dec 13 '21 at 15:47
  • 3
    `dart pub get` was the issue for me as well – Jake Boomgaarden Mar 24 '22 at 17:01
  • 1
    **Deleting the folder is important** I tried starting from step 2, it didn't work. You have to delete `/Users//.pub-cache` first – sharbel okzan Nov 30 '22 at 14:51
  • 1
    Thanks for highlighting `dart pub get`, that what I was missing. Apparently it depends on the package that causing the error, i.e. for some cases, `flutter pub get` do the trick but some times you also need to do `dart pub get` – sharbel okzan Feb 07 '23 at 09:12
21

run flutter clean and then flutter pub get

jestrabikr
  • 420
  • 5
  • 12
18

I looks like your pub cache is corrupted. You can try to run pub cache repair from the command line but I think that this is still not working when the pubspec.yaml file is missing (there was an open issue about this - found it: http://dartbug.com/21418). Please try to delete the folder /home/reza/.pubcache/hosted/pub.dartlang.org/browser-0.10.0+2 and then run pub get from within your project directory or from DartEditor.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
13

this will also occur if your pubspec.yaml file reffers to some other pubspec file. Try removing paths from the pubspec.yaml and replace with a version instead, like this.

flutter_local_notifications:
    path: ../

To This

flutter_local_notifications: ^4.0.1+1
MBK
  • 2,589
  • 21
  • 25
4

This solution works on the newer versions of flutter. If you can not find your pub cache, you will find it here:

C:\Users\[username]\AppData\Local\Pub

Delete the Cache folder
Run pub cache repair
Run flutter pub get

3

In my case, it happened after I was update flutter version.

cd to the current project folder.

 flutter clean
 flutter pub get

finally flutter packages pub run build_runner build It's Worked~

iDevOrz
  • 730
  • 8
  • 16
2

Thanks for David's answer which helped me to find and delete pub cache directory in my mac.

sudo rm -Rf /Users/<user-name>/Developer/flutter/.pub-cache

There's a change in the path mentioned by David.

Abdul Saleem
  • 10,098
  • 5
  • 45
  • 45
2

Update #1: Flutter 3.0.1

Had a very similar error message recently after running flutter doctor :

Building flutter tool...
Could not find a file named "pubspec.yaml" in "/opt/flutter/.pub-cache/hosted/pub.dartlang.org/test-1.20.2".
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
Could not find a file named "pubspec.yaml" in "/opt/flutter/.pub-cache/hosted/pub.dartlang.org/test-1.20.2".
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (8 tries left)
^CError: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (7 tries left)

Resolved by:

  1. Login as authorized user
  2. Add group permission to the folder tree using sudo chmod -R g+rwx /opt/flutter

Note - Problem reappeared after upgrading Flutter to 3.0. This seems to confirm that the default flutter permissions did not respect my group ownership for all new files. Following the fix to the group permissions, flutter was able to complete my upgrade to 3.0.1.

Original Answer:

Note: My initial error was pointing to this particular folder.

/opt/flutter/bin/cache/pkg/sky_engine
  1. I touched the pubspec.yaml file and then did a cat on the file to confirm that it existed. The file was there with all the yaml type info.

  2. Next I checked the permissions (using ls -ll) and noticed that my group did not have the correct permissions set to the pubspec.yaml file in the folder. (my user-account doesn't own the folder but my group has access)

  3. After logging in as the authorized user account; I changed the group permissions using sudo chmod -R g+rwx /opt/flutter/bin and then verified my permissions on the files in the target folder.

  4. Ran flutter pub get from the project folder with no more trouble.

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
2

For windows, cleaning the pub cache worked for me, I am also using Flutter version manager

flutter pub cache clean

then use

flutter pub get

just add fvm at the start if you're also using it

1

The simple solution would be to delete your .pub-cache folder and then pub get again.

F.K
  • 93
  • 7
1

I had the same problem. to resolve the problem I tried many ways suggested on the internet, but nothing worked. then I went to the path C:\Users\pc\AppData\Local\Pub\Cache and deleted "Cache" folder and after deleting this folder I restarted IDE and run the "pub get" command and it solved this problem.

1

FileSystemException(path=/Users/username/Documents/development/flutter/bin/cache/pkg/sky_engine/lib/_embedder.yaml; message=Cannot open file) [SEVERE] mobx_codegen:mobx_generator on lib/view/main/squad/viewmodel/view_model.dart (cached):

  1. sudo chmod -R g+rwx /Users/<username>/Documents/development/flutter
  2. rm -rf cache
  3. sudo rm -Rf .packages
  4. flutter clean
  5. flutter pub get
  6. finaly flutter packages pub run build_runner build
artemitSoft
  • 286
  • 5
  • 17
1

It worked for me.

sudo rm -Rf /Users/username/Desktop/flutter/.pub-cache

take care, the path must be right!

Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
1

For Windows user

C:\Users\UserName\AppData\Local\Pub\Cache

Delete this Cache folder

Then, go to project, run

flutter pub get
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

For me neither worked deleting .pub-cache or packages from project root. The solution was removing the directories from ~/.pub-cache/git seperately.

In my case I have had 6 packages hosted on git so I have had to remove each package and call flutter pub get every time for all the 6 packages. After doing that, everything seems working perfectly fine.

0

You don't have to delete or repair the entire cache (takes a long time)

You can simply delete the problematic package, in this specific case: /home/reza/.pubcache/hosted/pub.dartlang.org/browser-0.10.0+2"

But make sure to copy the value from your error message.

Then run: flutter pub get or pub get

Yonatan Naor
  • 1,367
  • 18
  • 19
0

1.Just delete flutter from root folder like "C:/src/flutter".

2.Download from here https://docs.flutter.dev/get-started/install/windows

3.Set the path inside user variables under Edit environment variables.

4.Then just reset the path on android studio....

after that the problem will be gone.

Tanvir Ahmed
  • 564
  • 6
  • 13
0

In my case I had some error in pubspec.yaml file, after fixing the error in pubspec.yaml the error disappeared

0

On MacOs I had to run:

sudo rm -Rf /opt/homebrew/Caskroom/flutter/2.8.1/flutter/.pub-cache

Prior to this I tried most of the above but was still getting the same error, 'cannot find a .yaml' file

0

I resolved this issue using these steps in MacOS:

  1. First running Flutter clean
  2. Running "sudo rm -Rf packages" in terminal
  3. Going to correct package directory where "pubspec.yaml" file is located
  4. Running "flutter pub get" in terminal
  5. Checking that "builder_runner" package is in "pubspec.yaml" file.
  6. Running "flutter packages pub run build_runner build" in the terminal.
WasimSafdar
  • 1,044
  • 3
  • 16
  • 39
0

After trying many solutions, I found one that works for me.

  1. Delete all libraries from flutter->.pub-cache->hosted->pub.dartlang.org
  2. And run the given below commands in terminal,
flutter clean
flutter pub get

Note: Run above commands in terminal not from Tools->flutter->flutter clean / flutter pub get

0

enter image description here

Put your flutter sdk path before your original command, remove the flutter before the original command

> D:\sdks\flutter3.3.10\bin\flutter.bat pub run

then simply press enter

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
0

i solved this error, by removing local reference path which were not exist in path: ../. i were using

 flutter_overlay_window:
        path: ../

replace above to this below code

flutter_overlay_window: ^0.10.5

flutter_overlay_window this can be any package.

Karamat Subhani
  • 104
  • 1
  • 7
0

Deleting the cache isn't necessary, the issue means the pkg couldn't be found in the cache.. simply install/activate the pkg to make it globally accessible using;

dart pub global activate package_name

In my case, Flutterfire was failing to run.

emma-ea
  • 324
  • 2
  • 5
-1

pub get failed (66; Could not find a file named "pubspec.yaml" in "/Users/osx/flutter/.pub-cache/hosted/pub.dartlang.org/ percent_indicator-3.0.1".)

Solution

The simple solution would be to delete your /osx/flutter/.pub-cache folder and then flutter pub get.

-1

in my case, could be yours too, I am linux(debian) user, I've a problem like this :

Could not find a file named "pubspec.yaml" in "/opt/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1".
pub finished with exit code 66

and i fix it, with following comands:

sudo rm -Rf /opt/flutter/.pub-cache
sudo rm -Rf packages
flutter pub get
Marcelo Cesar
  • 89
  • 1
  • 4
-2

I got the same error and tried to resolve it by going to the location displayed in the debug console, deleting the packages directories displayed there, and then running pug get

Santhosh
  • 1
  • 1