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

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 :-
Go to terminal
Then find local tabs
Then click on a '+' sign and type your command.This should solve
your error
See this screenshot as a guide.

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.

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
flutter clean
flutter run
Note: cd stands for Change directory
I hope this helps!

ERROR is simple You are in the wrong directory and trying to run your command in CMD in the wrong directory.
SOLUTION:
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))
Now try to run your command it will work fine.

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

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.

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.

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:
Clone flutter or unzip flutter sdk (you have downloaded) and move the flutter folder to C drive.
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.
If it is installed, move to any folder where you want to create your project and type this command "flutter create project_name"
Now move to the folder you have recently created and then run "flutter run" from that folder
I think this will surely help you.

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

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

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.

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.

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

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 :
Open terminal
flutter clean
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

You need to execute the following command:
flutter pub global activate webdev

Related

Permission denied on running globally activated dart package

I'm trying to develop a command line package so I followed these steps:
dart create --template=package-simple package_name
then activating the package globally with:
dart pub global activate --source path $(pwd)
note that I didn't find anything in the documentation about --source path actual_path but whenever I use the command only with --source actual_path I get the following:
"/Users/user/Desktop/Workspace/package_name" is not an allowed value for option "source".
So after successfully activating the package I tried to run it using:
package_name
But I got this:
zsh: command not found: package_name
Found out that the documentation here is outdated and after searching the local directory I found the actual directory is global_packages not bin, and so I've changed it.
Now when I try package_name I get:
zsh: permission denied: package_name
After investigation I found that package_name is a directory in the global_packages directory and it only contains pubspec.lock so I've tried chmod a+x on the file and the directory with no avail.
Further investigation the global_packages contained another package intl_utils inside I found:
.packages incremental
.dart_tool bin pubspec.lock
But running intl_utils on the terminal too get's me the same error:
zsh: permission denied: intl_utils
I didn't install the package manually but the VS Code extension Flutter Intl did and it seems to work perfectly fine.
Now I have two questions:
permission denied on what exactly since the Flutter Intl extension works perfectly???
I have a file in my package bin/my_package.dart but it didn't go there, am I doing something wrong?
I'm running dart through flutter:
Flutter (Channel master, 2.13.0-0.0.pre.90, on macOS 12.3 21E230 darwin-x64, locale en-US)
dart --version
Dart SDK version: 2.17.0-202.0.dev (dev) (Thu Mar 10 20:55:41 2022 -0800) on "macos_x64"
Edit #1
Tried dart pub global run package_name and it worked but it seems like it's building the package again, but still I need to use it without the long line the correct way.
Edit #2
To create the app I've tried
dart create -t console-full package_name but still with the same results.
So after messing around and changing the branch (a lot) turns out the problem is in the pubspec.yaml where there should be :
executables:
package_name: # you can add a custom path here if you want though
And I guess the docs were right about "bin" directory but it left me wondering about global_packages and intl_utils

How can I fix "Checking Dart SDK version... << was unexpected at this time" error in Flutter?

I am facing an issue any time I try to run any app or flutter command from the terminal, this is displayed: Checking Dart SDK version... << was unexpected at this time.
Not even flutter doctor works.
Nothing seems to work and it's so frustrating as it happened out of the blue. One moment everything was fine, now nothing works. Any help will be appreciated
I've resolved this error with the below steps:
Go to C:\Users\{Name}\.gradle} - Delete the .gradle directory.
Then Download and install the same flutter and dart SDK version in some other location and set the environment variables.
Example:
Environment variables Before :
("D:\FlutterExtractedFiles\flutter\bin")
("D:\FlutterExtractedFiles\flutter\bin\cache\dart-sdk\bin")`
Environment variables After :
("C:\edgedownloads\flutter_windows_v1.12.13+hotfix.8-stable\flutter\bin")
("C:\edgedownloads\flutter_windows_v1.12.13+hotfix.8-stable\flutter\bin\cache\dart-sdk\bin")
Then check the Android Studio event log
I've resolved this error by following these steps:
Go to folder C:....\Flutter\
Run this command: git reset --hard HEAD
This will restore the flutter SDK folder to its original state, so no need to reinstall the SDK.
Flutter reinstalled worked for me..
delete flutter folder in C directroy.
make a src folder in C: directory.
GoTo cmd and install flutter from official flutter github repoC:\src>git clone https://github.com/flutter/flutter.git -b stable
https://flutter.dev/docs/get-started/install/windows
run flutter doctor
set env path.
DONE
What worked in my case was deleting the .gradle file (C:\Users\USER.gradle) and reinstalling Flutter in another location and changing the PATH to it.
you should try this
restart your pc and delete the flutter folder in C directory then reinstall flutter and run flutter doctor
For me, the following steps resolved the problem:
Open cmd and run flutter doctor. (if there is an issue resolve them first.)
If not then change the flutter channel to dev. Whatever your channel is?. If this is the dev channel then change to master channel.
Again flutter doctor. If everything goes perfectly. then run your project. If it runs accordingly then again change to channel to stable.
I faced this error before, all I had to do was to:
Remove Flutter from my C directory.
Install Flutter from the official website.
Run Flutter doctor: flutter doctor
No need for changing the PATH or any further actions.
If it worked fine with you then you are all done!
I faced another error after it, related to the Dart SDK and solved it using this link
the key is to install Android SDK Command-line Tools, steps being:
Open Android Studio Tools Menu, SDK Manager In the window that comes
up there are inner panels, choose SDK Tools panel Tick Android SDK
Command-line Tools Choose Apply button near the bottom of the window
At that point, you will be prompted to accept the SDK license and the
command line tools will be installed. Your license issue should now be
resolved.
If your using Intelij and get the << error and none of the above work.
Delete the .intelij folder in your project and reopen the folder in intelij.
I faced this problem too and I've solved it by downloading SDK file again.

NativeScript IOS project.pbxproj not found

I am trying to run the hello world nativescript app using the command "tns run ios" but i am getting "Unable to apply changes on device: <device id>. Error is: ENOENT: no such file or directory, open '/<path_to_project>/NativeTest/platforms/ios/NativeTest.xcodeproj/project.pbxproj'.". Running it in Xcode works. I really ran out of ideas . Also, i checked and the file is actually there
After hours of time spent with this issue i found a fix, so maybe my answer would help somebody else. The issue was caused by me setting in XCode the dev team in the project. After i set the team project for the current project, i create a new project and it automatically got the team id i set at the old project without my intervention and now it works without errors. Yay
ns clean did it for me like it told me to do 😆 The platforms/ios folder appears to be invalid. If the build fails, run 'ns clean' and rebuild the app.
I was running npm run ios

Flutter run command error : FlutterView.send called on a detached view

Can anyone tell me why my app is not installing at all and ending with the error message
Observatory connection never became ready.
the app was working perfectly fine until yesterday .
I have changed the channel to master yesterday in the command prompt and from then on the app never runs.
I even switched back to channel alpha but still no use.
I have attached a screenshot of the command prompt where the installation was stuck forever.
I am not so sure if I need to reinstall the flutter. I am worried if I uninstall the flutter now it may not configure properly and I might break it forever.
Please can someone tell me what exactly might have gone wrong.
Many Thanks,
Mahi
Instead of reinstall try with following: (Mac)
Set Path Variable: via following terminal command
export PATH=~/flutter/bin:$PATH;
that is bin folder path of flutter.
export PATH=[PATH_TO_FLUTTER_GIT_FOLDER]/bin:$PATH
https://flutter.io/setup-macos/#update-your-path
If above not worked. Check with the Dart version
dart --version
Install the latest dart version:
brew install dart --devel
Hope this helps others.
For Mac
open terminal
$ echo $PATH
it will show like this
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
it means you need to add flutter in to path
Open Finder presss command + shift + G
Put /etc/paths in dialog and press GO
Copy the file "paths" and paste it on desktop
Then open the pasted "paths" file from desktop
and add following line into end of the file "/flutter/bin"
Then copy that file and again paste it on /etc/paths
same like step no 2
it will ask you to replace or not
press replace
Now if you hit $ echo $PATH on terminal it will show
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/swagat/development/flutter/bin
Now your $flutter doctor will work perfectly
The solution is from Google Groups #Flutter-Dev
Thank you very much for your reply #Michael Thomsen.
I've tried what you have suggested and the details are as follows:
When I used flutter run -v command the command prompt output is as follows:
It was stuck for a while at waiting for port connection if I am not wrong.
So I've used AndroidStudio, File>Open and selected android/ folder to run the app then the gradle was showing an error:
Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (25.2.0) and test app (25.4.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I modified the build.gradle(Module:app) to show the correct version of 25.2.0 which was previously showing 25.4.0.
dependencies {
androidTestCompile 'com.android.support:support-annotations:25.2.0'
}
I just saved the changes inside android studio and the gradle sync completed without any errors.
Now I can run the app from inside Android Studio and also from IntelliJ IDE.
Thanks very much Michael this solved my problem.
Reinstalling flutter would be my starting point. If this problem persists, please post the output of $>flutter doctor and a description of what exactly leads to this error.

Pub does not download dependencies on Windows 7 after the update to lib v2 (SDK 0.3.1_r17328)

After the update to the version 0.3.1_r17328 of Dart SDK and Dart Editor I have some trouble to import some library particulary Args library. I have the same problem both directly importing Args or importing Web_ui where Args is one of the dependencies.
Here is my pubspec.yaml:
name: notes
description: A sample application
dependencies:
web_ui: 0.3.0+1
or:
name: notes
description: A sample application
dependencies:
args: 0.3.1+1
Here is the error generate from build.dart
Unable to open file: C:/Users/Fabio/Dropbox/progetti/note/packages/args/args.dart'package:web_ui/component_build.dart': Error: line 25 pos 1: library handler failed
import 'package:args/args.dart';
'file:///C:/Users/Fabio/Dropbox/progetti/note/build.dart': Error: line 1 pos 1: library handler failed
import 'package:web_ui/component_build.dart';
I solved the problem. It seems that the Cache folder (Pub) has been corrupted.
I have deleted the folder Cache: C:\Users\<UserName>\AppData\Roaming\Pub
Then i run pub install from command line and it works.
Unfortunately, I was getting the same error with my windows XP machine.
In the end, I logged into my windows 7 machine and was able to
download the packages, zipped them up and pasted the libraries into my
windows XP dart editor. Success!
I had no reason to believe I had the exact proxy issue #shindokaku had as I am using my home computer.
I tried all the suggestions on deleting the .cache files, pub.lock files and the packages folder and retrying. I uninstalled dart editor and tried again. I also tried using the git resources to download web-ui and running commands through the command line to no avail
Including suggestions in this similar questions:
cannot-find-referenced-source-packages
is-there-a-workaround-for-pub-dependency-resolution-through-proxies
This problem has been haunting me over and over for a few weeks. I am not using Windows, so this answer is not intended to help the original poster who is using Windows 7.
If you are using Linux here are the steps I use to repair corrupted pub cache.
Go to the top level directory of your app. You should see at least pubspec.lock, pubspec.yaml, a folder named packages, and a folder named web.
Delete your pubspec.lock, and packages folder.
[Make sure you aren't storing your own libraries in the packages folder]
cd ~/dart/myApp/
rm -r packages
rm pubspec.lock
Now once you have removed these files:
pub cache repair
Note 1: if your dart-sdk is not in your systems $PATH, than you will want to use the absolute path to the sdk when using the above command. Comment if you need that explained.
Note 2: This is working solution with Dart 1.5.3. I have not tested this on earlier versions.
Try deleting your pubspec.lock file and packages directory in the root folder of the project. Then run pub install again, when things get wacky thats what I do.
You should try to run pub update. I have sometimes found that this doesn't work as expected from the editor, but generally works quite smoothly when called from the command line.

Resources