49

I am using Windows 10 with VS Code, although I also tested it on PowerShell, and both produced the same result:

After creating a new flutter program, before editing anything, I tried to run it on my phone, as the Tutorial Says, but I get an error saying "No pubspec.yaml file found". I thought that the issue must be that the default new app setup having an issue, so I used the "flutter_gallery" example. However, this had the exact same issue. I have reinstalled flutter, installed dart 2 on its own, deleted .pub-cache, but nothing works. I tried Googling the issue, but I couldn't find anything.

EDIT: I am running the commands from the root directory of the flutter project, where the pubspec.yaml file is, but I still get an error. The full error message is:

Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.

here is the result of running dir from the root of the project:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
da---l       2018-04-11   3:45 PM                .idea
da---l       2018-04-11   3:45 PM                android
da---l       2018-04-11   3:45 PM                ios
da---l       2018-04-11   4:19 PM                lib
da---l       2018-04-11   3:45 PM                test
-a---l       2018-04-11   3:45 PM            120 .gitignore
-a---l       2018-04-11   3:45 PM            292 .metadata
-a---l       2018-04-11   3:45 PM           5425 .packages
-a---l       2018-04-11   3:45 PM            851 hello_world.iml
-a---l       2018-04-11   3:45 PM           1412 hello_world_android.iml
-a---l       2018-04-11   3:59 PM           8882 pubspec.lock
-a---l       2018-04-11   3:59 PM            358 pubspec.yaml
-a---l       2018-04-11   3:45 PM            160 README.md

UPDATE: I still don't know what caused the problem, but when I reinstalled flutter for Beta 3, it finally worked.

James M
  • 541
  • 1
  • 5
  • 7
  • Can you post the console outputs? It help us to help you. – betorcs Apr 12 '18 at 02:19
  • What directory are you running `flutter run` in? The root directory of your project with the `pubspec.yaml`? – Dan Field Apr 12 '18 at 03:32
  • I have updated the question with console outputs. @DanField I am running from the root directory. I have updated the original question with that information. Thank you! – James M Apr 12 '18 at 15:31
  • "from the root directory" means from the root directory of your Flutter project, not from your system/disk? What is the output of `flutter doctor -v`? Where do you get the information that deleting `.pub-cache` should help? (was mentioned quite a lot recently) – Günter Zöchbauer Apr 12 '18 at 15:35
  • 1
    Can you include the output of a `dir` command in that folder? – Dan Field Apr 12 '18 at 15:43
  • @GünterZöchbauer Yes, the root of the flutter project. I have corrected that in the post. flutter doctor -v returns no issues. I got the suggestion about deleting .pub-cache from a similar question https://stackoverflow.com/questions/27217278/could-not-find-a-file-named-pubspec-yaml-in – James M Apr 13 '18 at 02:02
  • @DanField the `dir` command output has been added. – James M Apr 13 '18 at 02:06
  • The answer you linked to is not related because it's about a `pubspec.yaml` somewhere in `~/.pub-cache/...` was not found. Your case is about it not being found in the current directory. – Günter Zöchbauer Apr 13 '18 at 02:43
  • @GünterZöchbauer well I guess it's no suprise that didn't fix the problem then... – James M Apr 14 '18 at 00:38

29 Answers29

54

Looks like you are running flutter run command from a different directory (maybe parent directory).

Try running flutter run command from the project directory.

rohan parab
  • 1,589
  • 1
  • 14
  • 18
40

To solve this error in the EASIEST WAY follow below steps :-

  1. Go to terminal

  2. Then find local tabs

  3. Then click on a '+' sign and type your command.This should solve your error

See this screenshot as a guide.

Nico Griffioen
  • 5,143
  • 2
  • 27
  • 36
raman raman
  • 1,655
  • 4
  • 22
  • 34
  • This should be the accepted answer. I have tried this on an existing app and it worked fine. Thank you so much, you saved my time. Thumbs up! – Amimul Ihsan Apr 09 '23 at 16:49
12

Answer

Just change your directory folder project on terminal VS code.

Example

I save my project on directory D:\Project\Flutter Project\MyFirstApp and the main.dart on the directory name first_app.

Just typing like this on terminal:

cd first_app

Now we're on D:\Project\Flutter Project\MyFirstApp\first_app.

and then type flutter run.

Hopefully answer your question.

Example image

My Car
  • 4,198
  • 5
  • 17
  • 50
Adhim Bagas
  • 131
  • 1
  • 3
9

I had the same issue, then I realized by default, I was running flutter clean in my sub folder. Not the project folder. Definitely run as follows in the command terminal.

cd C:\Users*\Desktop*MyProject*my_project_flutter*

then run the following

  1. flutter clean
  2. flutter run

Note: cd stands for Change directory I hope this helps!

Payne Danger
  • 139
  • 1
  • 2
  • flutter command is not working 'flutter' is not recognized as an internal or external command, operable program or batch file. – Rahul Kushwaha Dec 31 '20 at 08:13
6

ERROR is simple You are in the wrong directory and trying to run your command in CMD in the wrong directory.

SOLUTION:

  1. First move to the directory in which pubspec.yaml is located. (Like in my case it is C:\Users\A12\AndroidStudioProjects\work1 (A12 is my username and work1 is project name))
  2. Now try to run your command it will work fine.
logify
  • 1,497
  • 1
  • 6
  • 7
5

@James M, go to command prompt and run

flutter upgrade

and then try to create a new project using the command

flutter create new_project

It would work fine.

Abhishek Raj
  • 480
  • 4
  • 14
3

Maybe you should check to see if the project directory you opened is correct. I had this problem because the project directory opened to the project's parent directory. You must ensure that the file exists in the project directory you have opened.

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
ZhangYifan
  • 31
  • 2
3

You can use flutter clean command and then try

flutter run In your terminal

Aamil Silawat
  • 7,735
  • 3
  • 19
  • 37
2

For me the culprit was OneDrive. I had to reinstall Windows 10 and when I did, it offered to setup OneDrive for me automatically. I thought - great, one less thing... Then later I realized that it had set itself up with the Files On Demand option set to true. Microsoft never ceases to elicit a facepalm from me with the things they think are great ideas. Just to verify that this was the problem, I copied the entire folder to a temporary location on my hard drive that wasn't synced to OneDrive and it ran fine.

If something has been corrupted in the process of trying to build and run without all the files accessible, hopefully you have a recent commit from github (prior to putting the project on OneDrive) that you can clone. This is assuming your problem has the same cause as mine.

Daryl
  • 1,007
  • 1
  • 10
  • 10
2

Possible that you are running flutter commands from a different directory. Go to project directory and try running flutter commands from there.

Naimish Vinchhi
  • 775
  • 8
  • 12
2

It seems you are running command from the flutter sdk installed folder. Instead you should run the command from the project you have created.

Match your steps you have done from below mentioned steps:

  1. Clone flutter or unzip flutter sdk (you have downloaded) and move the flutter folder to C drive.

  2. Now check whether the flutter is installed properly or not by running command(flutter --version) from any folder. Make sure you have set the flutter path inside environment variable.

  3. If it is installed, move to any folder where you want to create your project and type this command "flutter create project_name"

  4. Now move to the folder you have recently created and then run "flutter run" from that folder

I think this will surely help you.

Gaurav Kumar
  • 331
  • 4
  • 5
2

Error: No pubspec.yaml file found. This command should be run from the root of your Flutter project.

It Simple means that your terminal is currently not in your flutter project the path of the directory is wrong,

Solve it by navigate to the flutter folder change directory Eg : cd portfolio

after changing the terminal directory path

C:\Android Studio Stuff\Flutter Project\portfolio> // your command

1

You should run it in the project folder. For Example: the project folder is named "first_app" and it is located in Documents, so the first go to Documents(cd Documents) then enter your project folder(cd first_app) and then run the command "flutter run".

MacBook-Pro-5:first_app username$ flutter run

Komal
  • 69
  • 1
  • 1
  • While running from project folder it shows that "'flutter' is not recognized as an internal or external command, operable program or batch file. " – Rahul Kushwaha Dec 31 '20 at 08:11
1

I am constantly getting this error for my sub-folder 'example':

<my project folder>\example: no pubspec.yaml found

Not sure how to get rid of it. However, the error does not affect anything.

polina-c
  • 6,245
  • 5
  • 25
  • 36
0

I saw this error for invalid pubspec.yaml content, like for example spaces before

name: my_app

like

    name: my_app`
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

step 1 : Add this to your package's pubspec.yaml file: url_launcher: ^5.0.2

step 2: When You come back to main.dart file you can see the get dependencies. when yo click on that link "flutter packages get" command will run. You can get the URL Launcher package

Nithesh
  • 206
  • 3
  • 8
0

This error gets thrown when you try to run flutter build apk command (at least, it was in my case) while not being in the project directory. Usually, a flutter app's project directory path (let's say it is in F drive, and inside a folder named apps, is as: F:\Apps\app_name

I had the same issue, and the culprit in my case was this path: F:\Apps\app_name\android which is without a doubt, NOT a project directory. So, all I had to do was type this command in terminal: cd .. which takes to the parent directory.

So, before running the command, make sure to check out the directory being shown in terminal.

dev404
  • 1,047
  • 8
  • 21
0

In my case, i was using a VS code in Windows 10 and when i created a new project by Flutter: New Project it failed to create the following project files & folders under the project location

  • android

  • ios

  • lib
  • pubspec.lock
  • pubspec.yaml and few more files.

I tried creating another project and that successfully created with all the necessary files.

Sound dumb but this is what exactly happened to me.

Hope it helps someone.

kaarthick raman
  • 793
  • 2
  • 13
  • 41
0

You should cd to project directory, you probably are not in you opened project's root directory. If you press '+' button (new session) at the top of Flutter terminal window it automatically changes to current project folder.

Mohsen Emami
  • 2,709
  • 3
  • 33
  • 40
0
  • Try this command: flutter --version
  • Be sure you are on stable channel. By running flutter channel you will see the current channel and for change it run flutter channel stable and flutter doctor commands.
Misagh
  • 3,403
  • 1
  • 20
  • 17
0

only make sure you are running terminal in the main project file that has got .yaml in it

fady ahmed
  • 39
  • 6
  • Please post your this type of answer in comment section if it contains code then its okay so please make sure in future – Jaimil Patel Apr 21 '20 at 06:39
0

In terminal write cd your project name. Then hit enter and then write flutter run

0

Got a similar error:

The directory ../ does not contain a pubspec.

This is because I was referring to a folder that did not have a pubspec.yaml file.

Solution:

Change from:

  file_picker:
    path: ../

To

  file_picker:
    path: ./
live-love
  • 48,840
  • 22
  • 240
  • 204
0

if you are a linux user, the copy this line. sudo chown -R username home/username/ this should give you permission to every file into home/username/

Marcelo Cesar
  • 89
  • 1
  • 4
0

In Visual Studio Code - > Update the Dart/Flutter Packages when prompted by VSCode.

This will install the pub-get packages required and will resolve the issue.

enter image description here

srt111
  • 1,079
  • 11
  • 20
0

This solution worked for me :

  1. Open terminal
  2. flutter clean
  3. flutter packages pub get
Ghazal
  • 123
  • 2
  • 9
-1

you can find this pubspex.yaml in flutter in following location \src\flutter\packages\flutter_tools open CMD change Directory into above location and now you can run flutter upgrades get and other command. This one is working complete fine for me. Hope this will work for you

vishva
  • 19
  • 3
-1

Please check your present working directory

RIYAS PULLUR
  • 13
  • 1
  • 4
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34195498) – Rohit Gupta Apr 16 '23 at 02:57
-4

You need to execute the following command:

flutter pub global activate webdev
Sunil
  • 3,211
  • 3
  • 21
  • 21