简体   繁体   中英

How do I fix "No pubspec.yaml file found" in flutter?

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.

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

Try running flutter run command from the project directory.

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.

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!

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

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

You can use flutter clean command and then try

flutter run In your terminal

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.

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.

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

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.

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.

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

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.

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

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

name: my_app

like

    name: my_app`

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

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.

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.

I'm also face lots of issue while setup flutter in VS code in ubuntu. But i had resolve all issues from this link follow all steps it will remove all issue : happy coding...

enter link description here

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.

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

仅确保您在包含 .yaml 的主项目文件中运行终端

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

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

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/

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.

在此处输入图像描述

This solution worked for me:

  1. Open terminal
  2. flutter clean
  3. flutter packages pub get

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

如果您没有 l10n 文件,则错误可能来自 pubspec.yaml 中的这一行,请尝试将其删除,然后运行 ​​pub get :

generate: true #delete this line

您需要执行以下命令:

flutter pub global activate webdev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM