Could not find a file named "pubspec.yaml" in

66.6k views Asked by At

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

30

There are 30 answers

4
David Notik On BEST ANSWER

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).

6
Günter Zöchbauer On

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.

0
F.K On

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

0
jestrabikr On

run flutter clean and then flutter pub get

0
Hitesh Nath On

For Windows user

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

Delete this Cache folder

Then, go to project, run

flutter pub get
0
jay mangukiya On

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

0
Tommie C. On

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.

0
Samet ÖZTOPRAK On

It worked for me.

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

take care, the path must be right!

0
Marcelo Cesar On

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
0
Yonatan Naor On

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

0
Shubham mogarkar On

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.

0
Mateusz Pietras On

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
Abdul Saleem On

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.

0
MBK On

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
0
emma-ea On

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.

5
amatkivskiy On

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

0
iDevOrz On

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~

0
ABHILESH GUPTA On

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.

0
Samson Francis On

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

1
Santhosh On

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

0
artemitSoft On

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
0
Benjamin James On

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

1
Pritam Das On
  1. rm pubspec.lock(MacOS)/del pubspec.lock(Win)
  2. flutter clean
  3. flutter pub cache clean
  4. flutter pub get

This should do the work.

0
luckyhandler On

In my case this error appeared after forking a package and trying to reference my fork. Turned out that

package:
  git:
    url: https://github.com/company/package.git
    ref: master

tried to search for a pubspec.yaml in the root of the repo which doesn't exist. So I had to tell my pubspec where to look.

package:
  git:
    url: https://github.com/company/package.git
    ref: master
    path: subfolder

This solved the issue for me.

0
BuggyBunny On

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
Jeffrey Palcone On

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
Mohammad Abd-Elmoniem On

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

0
Tanvir Ahmed On

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.

0
WasimSafdar On

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.
0
Karamat Subhani On

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.