Yarn is installed but does not work. Command is recognized but no yarn commands do anything. Windows Powershell - powershell

node version 11.13.0
npm version 6.9.0
I have installed yarn multiple ways, first with the npm install -g yarn, then I tried the .msi installer, and I also tried installing with chocolatey from an elevated shell. Usually, when I try to use something I have not installed, I get a message that looks like this:
PS C:\Users\[me]> hello
hello : The term 'hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hello
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (hello:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
However, yarn commands are recognized but do nothing.
PS C:\Users\[me]> yarn --version
PS C:\Users\[me]>
I've tried changing the Path environment variable to include the following:
C:\Users\[me]\AppData\Local\Yarn\bin
C:\Program Files (x86)\Yarn
C:\Program Files (x86)\Yarn\bin
but this didn't change anything.

you must be add %USERPROFILE%\AppData\Roaming\npm in environment path
1-search environment in the start menu
https://i.stack.imgur.com/y4zxD.jpg
2-Click environment variables
https://i.stack.imgur.com/B59yD.jpg
3-edit path of user variables
https://i.stack.imgur.com/Vz73p.jpg
4-add URI of yarn as new
https://i.stack.imgur.com/Rq7xK.jpg
then after that if can't use yarn command in vscode and get error yarn.ps1 cannot be loaded because running scripts is disabled on this system; open Powershell as Administrator and run below command
Set-ExecutionPolicy Unrestricted

--version is not a valid switch, use yarn version instead - https://classic.yarnpkg.com/en/docs/cli/version.

Even after adding environment variable on windows I got error. Here is fix
%USERPROFILE%\AppData\Roaming\npm in environment path
Open windows command shell as administrator and run command:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

For those who are not comfortable with changing Execution policy, here's a solution that worked for me:
Solution: the problem was one extra "\" was missing after bin.
Before: %USERPROFILE%\AppData\Roaming\npm
After: %USERPROFILE%\AppData\Roaming\npm\

Related

Why do I get an error running Get-WindowsCapability in PowerShell ISE on Windows Server 2012 r2?

I am running the PowerShell ISE on a Windows Server 2012 r2 machine.
When I run the following:
Get-WindowsCapability
I get the following error:
Get-WindowsCapability : The term 'Get-WindowsCapability' is not
recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again. At line:1 char:1
Get-WindowsCapability
+ CategoryInfo : ObjectNotFound: (Get-WindowsCapability:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Am I missing a PowerShell package?
How do get this feature working?
Thanks, JohnB
Get-WindowsCapability is a cmdlet from the DISM module.
DISM was deployed natively with Server 2012 R2, but depending on the version of PowerShell or other configuration settings (like where your Windows partition is setup or image specific customizations), sometimes we find that we need to import the module before using it, like so:
Import-Module DISM
#or, to see which commands are in the module
Import-Module DISM -Verbose
If this fails, double check that it wasn't removed somehow. For instance, does it appear when you run the following?
Get-Module DISM -ListAvailable
If it doesn't appear, then it seems the module was removed and maybe the Windows component. No worries, we can get it back with the module too by installing the Windows Automated Deployment Kit (ADK), found here.
Update: you may find the module under this path as well
C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\.
The module file to import would be under the x86\DISM folder or x64\DISM, and named dism.psm1
This command seems not to be available in Windows Server 2012. For a list of all available commands, see Deployment Image Servicing and Management (DISM).

PowerShell Install Module command not failing but not installing module

I am trying to install the PnP online commands for SharePoint onto my PowerShell however the following command doesn't seem to work;
Install-Module -name SharePointPnPPowerShellOnline -scope CurrentUser
The command seems to run through fine with no errors appearing but when I try to run Commands which should have been installed I get an error saying the commands can not be found.
connect-pnponline : The term 'connect-pnponline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ connect-pnponline
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (connect-pnponline:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have had a look at all the module folders and the module is not in any of them. I have compared my environment paths with a coworker who has this working and they are the same.
Does anyone know what might be causing this?
This was caused by by modules being stored on OneDrive. By default my module path was set to "%USERPROFILE%\Documents\WindowsPowerShell\Modules" but since i had OneDrive installed my path changed to "%USERPROFILE%\OneDrive\Documents\WindowsPowerShell\Modules".
To resolve this issue I went to Documents>Windows Powershell>Modules and copied the link. Then, via the Start' menu, I went to 'Edit the system environment variables'>advanced>Environment Variables, highlighted PSModulePath and clicked Edit.
Once in this window I clicked New and pasted the link I found above.
This resolved the problem I was experiencing.
The module probably isn't imported. You should be able to executeImport-Module SharePointPnPPowerShellOnline which should either import your module, or give you an error if it can't be imported for some reason.
To tackle the non-autoloading issue, check the following:
Check that you're setting $PSModuleAutoLoadingPreference and that it's not set to None or 0
Cmdlets which make use of a PowerShell provider do not get automatically imported
SharePointPnPPowerShellOnline implements a SharePoint provider so I'd wager this is the case.
I had the same symptom The term '' is not recognized..., but a different fix.
When I checked $ENV:PSModulePath in Windows Powershell (this problem was not present in pwsh powershell core), I saw the expected folder C:\Users\cwalsh\OneDrive\Documents\WindowsPowerShell\Modules was missing:
Instead $ENV:PSModulePath was ;;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
The root cause was I had PSModulePath env var defined at both User-level as ; (this is not how my other PC is set up), and at System-level as %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\. I guess unlike PATH this variable doesn't automatically concatenate both.
I deleted the user-level PSModulePath environment variable and now in a new process the module works as expected.
Onedrive syncing screwed up the files for MgGraph authentication.
one of the subfolders sync was broken he file was removed because "cloud" didnt know about it. Had to reinstall... Need to change the default location out of documents if you have onedrive so silly

Error while activating virtual environment in Windows 10 PowerShell

I get an error while activating virtual environment in Windows 10 PowerShell :
PS C:\Users\sunil\Desktop\my_projects> .\venv\Scripts\activate.ps1
.\venv\Scripts\activate.ps1 : The term '.\venv\Scripts\activate.ps1' is
not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
Even trying this way:
PS C:\Users\sunil\Desktop\my_projects\venv> .\Scripts\activate
Program 'activate' failed to run: No application is associated with the
specified file for this operationAt line:1 char:1
+ .\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~.
If you are running Windows, then navigate to <venv>\Scripts, where <venv> is the name of your virtual environment. Then, execute the following command:
set-Executionpolicy -Executionpolicy Remotesigned -Scope CurrentUser
Type activate and press return. You will now be able to use your virtual environment.

Octopus Deploy not running PowerShell script

I have a Process Step in Octopus Deploy to run some Selenium WebDriver tests by calling a PowerShell script but it results in an error.
The PowerShell script is as follows:
set nunitPath="C:\AutomatedTests"
cd %nunitPath%\
nunit-console SiteCore.nunit /include:BulkyWasteTests
When the deployment takes place and the Process Step to run the script takes place, the following error occurs:
Set-Location : Cannot find path 'C:\Octopus\Work\20170110115049-7\%nunitPath%\' because it does not exist.
At C:\Octopus\Work\20170110115049-7\Script.ps1:2 char:3
+ cd %nunitPath%\
+ CategoryInfo : ObjectNotFound: (C:\Octopus\Work...-7\%nunitPath %\:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
The remote script failed with exit code 1
I don't understand why the error is reporting a different location to the location specified in the PowerShell script.
Any help greatly appreciated.
cd is an alias for Set-Location, so you can tell that it's the second line you need to change by looking at the error. Your cd line is trying to set the location to the %nunitpath% environment variable rather than the nunitPath script variable.
To reference the script variable use $nunitpath
So your script should look like:
set nunitPath "C:\AutomatedTests"
cd $nunitpath
nunit-console SiteCore.nunit /include:BulkyWasteTests
Edited with #4c74356b41 additional correct comment.
PowerShell doesn't use %variablename% syntax for expanding environment variable references in a string. That's cmd.exe syntax. In PowerShell, write $env:variablename instead.

Not able to execute AWS Powershell tool cmdlet in TFS Post build script

I am trying to execute the few aws cmdlet command in post build script with TFS build. I have a AWS SDK tool is installed in build controller. I am able to run the same commands manually in Build controller. But when i invoke those commands in TFS post build script. It's giving me error that its not able to find the cmdlet installed on the build controller. I tried to change the execution policy but didn't help. I have an execution policy - bypass right now. script is executing but only the commands is not able to execute. I am thinking that it's issue because of something like Execution policy. Do we need to check anything else same like execution policy while we invoke any third party cmdlet from power shell.
Commands:
Set-AWSCredentials -AccessKey -SecretKey
Set-DefaultAWSRegion -Region us-east-1
Write-S3Object -BucketName agero-source-package -File "\\b tfadfa\adfa\adf\asdf\adsf\asdf\asd\xyz.zip"
Error:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:41 char:26
+ cd "\\b-tfsbc001wv\C$" | Set-DefaultAWSRegion -Region us-east-1
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-DefaultAWSRegion:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Write-S3Object : The term 'Write-S3Object' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:43 char:26
+ cd "\\b-tfsbc001wv\c$" | Write-S3Object -BucketName agero-source-package -File " ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
From the error messages, it would appear that the AWSPowerShell module cannot be found/automatically loaded by whatever account the TFS build process is running as.
Check that the module is installed to a globally available location under which the version of PowerShell you have searches for modules or, that the path to the module folder is present in the $PSModulePath environment variable for the TFS build account.
I got the same error on my TFS Build Agent:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
After I installed AWS Command Line Interface x64 bit (AWSCLI64) I was able to set the Set-DefaultAWSRegion by stepping over the line of code.
I was getting this error until I ran Powershell using "Run as Administrator." So the problem might be with permissions.