Permission denied on running globally activated dart package - dart

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

Related

Flutter Installation Issue

I have macOS sierra 64 bit, and I am trying to install flutter SDK kit.
When updating my path to export PATH=$PATH/Users/mayankvaswani2008/Developer/flutter/bin and using the command
echo $PATH
I get this path
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin/Users/mayankvaswani2008/Developer/flutter/bin
then when I type flutter doctor or flutter by itself, it says that
-bash: flutter: command not found
Please help
As pskink said,
You need to add in a colon between paths in MacOS. You'll want to go in and remove the flutter path, then run this: PATH=$PATH:/Users/mayankvaswani2008/Developer/flutter/bin
Should do the trick.

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

stagehand command not found when trying to create new application

I just installed stagehand on my mac and the install went off without a hitch, but when I try using it to spawn a new dart application I get this error -bash: stagehand: command not found. Any ideas?
I've looked at my machine, and stagehand is in ~/.pub-cache/bin which I think I had to add to my .profile manually:
export PATH=$PATH:~/.pub-cache/bin
(edit: I've just found the confirming information tucked away in the pub pages: https://www.dartlang.org/tools/pub/cmd/pub-global#running-a-script-from-your-path)
I'm on mac too. I did this:
brew tap dart-lang/dart
brew install dart
stagehand
zsh: command not found: stagehand
And then this command fixed it:
pub global activate stagehand
Now it works:
stagehand
Welcome to Stagehand!
I came across same issue on my windows pc. I had to check flutter installation directory and add following .pub-cache\bin directory to Windows path environment variable.
D:\flutter\.pub-cache\bin
I think this might be helpful to any Windows user.
On MacOS run this command: export PATH="$PATH":"$HOME/.pub-cache/bin"
I installed it, but still gave me error not found, but I noticed warning in following message after running the command:
Package stagehand is currently active at version 3.3.11.
Resolving dependencies...
The package stagehand is already activated at newest available version.
To recompile executables, first run `global decativate stagehand`.
Installed executable stagehand.
Warning: Pub installs executables into C:\Users\Nijat\AppData\Local\Pub\Cache\bin, which is not on your path.
You can fix that by adding that directory to your system's "Path" environment variable.
A web search for "configure windows path" will show you how.
Activated stagehand 3.3.11.
The problem is this line:
Warning: Pub installs executables into C:\Users\Nijat\AppData\Local\Pub\Cache\bin, which is not on your path.
Thus, you also need to add that to your environment variables. This solved my problem and now I can run stagehand.

Cordova throws syntax error when trying to add platform

I'm trying to install Cordova and Ionic Framework on a Ubuntu server. I already used Node.js on it, so simply ran:
sudo npm install -g cordova
Then I cloned a sample project from GitHub
sudo git clone https://github.com/driftyco/ionic-weather.git
I entered the directory and tried to add the iOS platform library in order to build it:
cd ionic-weather
sudo cordova platform add ios
However it throws the following error:
Creating ios project...
/home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: 33: /home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: Syntax error: "(" unexpected
Error: /home/benedict/.cordova/lib/ios/cordova/3.4.0/bin/create: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/src/superspawn.js:112:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
I've tried reinstalling Cordova in case something got corrupted, but no luck. I can't seem to find anyone else with this issue either so I'm kinda stuck. Any ideas?
This turned out to be a combination of several problems:
Ant is a required dependency, although it's not documented as a dependency as far as I can tell from any of the install guides the ionic guide or cordova guide point to. In fact I found this out by digging around SO and a few other dark corners of the internet
JDK must also be installed. (not just JRE)
2 folders have to be added to the path (for Android anyways).
Ant
This can be installed via sudo apt-get install ant.
jdk
sudo update-alternatives --config java
first, you can find out if you have jdk by running `sudo update-alternatives --get-selections | grep ^java
if you already have the jdk, you can update your jre to the jdk version using sudo update-alternatives --config java
if not, then install jdk (not just the jre), using sudo apt-get install openjdk-7-jdk
Path setting in ~/.bashrc
$ cd ~
$ sudo vi .bashrc
at the bottom, before the PATH= add the path to the bundle folders for both platform-tools folder and the tools folder under the sdk folder. Several of the guides only mention the platform-tools folder.
The guide specifically mentions ios can't be installed on Windows, but strangely leaves out Linux. This may be an oversight, but I can't be sure. There was some indication in the ionic guides that ios emulation could be done on linux, even though actual development could only be done on OSx.
the ios platform requires xcode 4.5 with cordova, which needs OSx 10.7 you basically can't add the ios platform tools on Windows or Linux. Unfortunately cordova and ionic both seem to forget Linux exists, and therefore the docs imply this will run on Linux when they note inoperability on Windows but say nothing about Linux.
Your problem is that your trying to build the app on a machine that doesnt have Mac OS installed. In order to add IOS platform you need to run this command on a mac.
Check the Prerequisites here:
http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html

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