Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Powershell Disabled by default #213

Open
randomaxess opened this issue Nov 18, 2022 · 7 comments
Open

Windows Powershell Disabled by default #213

randomaxess opened this issue Nov 18, 2022 · 7 comments

Comments

@randomaxess
Copy link

randomaxess commented Nov 18, 2022

Info
Windows: 10 v19045.2251
Node: v18.12.1
Yarn: v3.3.0

Issue
Windows does not allow powershell scripts to be run by default.

In full:

yarn : File C:\Program Files\nodejs\yarn.ps1 cannot be loaded because running scripts is disabled on this system. For more inf 
ormation, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn -v
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Replication
As administrator run the following console commands:
corepack enable
corepack prepare yarn@stable --activate
yarn -v

Sollution
If you have access to overwrite the global powershell policies, this is easy to solve. In many Enterprice settings this isn't going to be an option, however, even when you have the local administrative rights to run the "corepack" commands on your local machine.

What you can do, is to rename the "yarn.ps1" file to something like "yarnABC.ps1". Then the system seems to default to the "yarn.CMD" file instead, which works just fine.

Powershell files in corepack
I'm not sure why "corepack enable" creates .ps1 files for the corepack utilities, when there aren't any for npx or npm, but this will cause an issue in a lot of Enterprise settings, and if the .ps1 files aren't necessary, then maybe they could be removed in a future update?

@aduh95
Copy link
Contributor

aduh95 commented Feb 24, 2023

What you can do, is to rename the "yarn.ps1" file to something like "yarnABC.ps1". Then the system seems to default to the "yarn.CMD" file instead, which works just fine.

Another "workaround" is to always prefix the yarn command with "corepack", e.g. corepack yarn start. Not ideal of course, but it might unblock you as it should work in all cases corepack itself is available.

We could introduce a new env variable to disable the creation of .ps1, or maybe a CLI flag (e.g. corepack enable --no-powershell). I'm not familiar enough with Windows to know if not having .ps1 by default would make sense, but making it opt-out would be a good first step I think. Would you like to contribute a PR?

@asvishnyakov
Copy link

This is a definitely a problem for Windows users after upgrading to yarn 4.

@merceyz
Copy link
Member

merceyz commented Feb 9, 2024

Another option is to add aliases to your PowerShell profile as documented here: https://github.com/nodejs/corepack/tree/b9eea589b4535d32b8e9ca1e884c3a44bf7d99ea#corepack-enable--name

@asvishnyakov
Copy link

It's a require additional steps by developers, while previously it was just clone and go solution with yarnPath

@merceyz
Copy link
Member

merceyz commented Feb 9, 2024

This is off-topic but you can still use yarnPath if you want https://yarnpkg.com/cli/set/version#options.

@asvishnyakov
Copy link

I think the real solution for this issue will be just sign this scripts with the same key as used for Node.js itself.

@zkochan
Copy link

zkochan commented Aug 21, 2024

Isn't this script basically dynamically created? I don't think that it is a static file that can be presigned. Just don't create a ps1 file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants