29
votes

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.

24
Can you post the console outputs? It help us to help you.betorcs
What directory are you running flutter run in? The root directory of your project with the pubspec.yaml?Dan Field
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
"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
Can you include the output of a dir command in that folder?Dan Field

24 Answers

29
votes

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

Try running flutter run command from the project directory.

26
votes

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.

8
votes

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!

4
votes

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

3
votes

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.

enter image description here

3
votes

You can use flutter clean command and then try

flutter run In your terminal

2
votes

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.

2
votes

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.

2
votes

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

2
votes

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.

1
votes

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.

1
votes

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

0
votes

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

0
votes

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

name: my_app

like

    name: my_app`
0
votes

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

0
votes

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.

0
votes

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.

0
votes

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.

0
votes
  • 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.
0
votes

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

0
votes

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

0
votes

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: ./
-1
votes

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

-4
votes

You need to execute the following command:

flutter pub global activate webdev