berry icon indicating copy to clipboard operation
berry copied to clipboard

Potential yarn 2 package.json scripts execution privileges issue

Open mikematos84 opened this issue 3 years ago β€’ 6 comments

We have started using yarn, specifically yarn 2, over npm in our repo and I have recently been running into an issue locally that I can't solve:

I have the following script in package.json to run our storybook with some parameters:

"scripts": {
  ...
  "storybook": "start-storybook -h www.custom-local-domain.com -p 6006 --https --ssl-key ~/path-to-certs/cert.key --ssl-cert ~/path-to-certs/cert.crt",
  ...
}

Before we upgrade to yarn 2, we could simply run npm run storybook and this would run fine. Now if run yarn storybook it starts to spin up storybook but then errors out and I get something like the following:

➜directory git:(feat/branch) βœ— yarn storybook
info @storybook/react v6.3.4
info 
info => Loading presets
ERR! Error: ENOENT: no such file or directory, open '~/path-to-certs/cert/crt'
ERR!  [Error: ENOENT: no such file or directory, open '~/path-to-certs/cert.crt'] {
ERR!   errno: -2,
ERR!   code: 'ENOENT',
ERR!   syscall: 'open',
ERR!   path: '~/path-to-certs/cert.crt'
ERR! }

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

This seems weird to me since, besides the change to using yarn 2, nothing else has changed. No privilege level of the files or folder have not changed at all and furthermore, if I run the command directly in the terminal start-storybook -h www.custom-local-domain.com -p 6006 --https --ssl-key ~/path-to-certs/cert.key --ssl-cert ~/path-to-certs/cert.crt it runs without a problem as well.

This makes me lean towards a privileges error within yarn when executing the scripts found in the package.json. Is there something I am doing wrong here? Is this a known issue with yarn 2?

Looking for whatever help I can get.

Thanks, everyone.

mikematos84 avatar Jul 29 '22 15:07 mikematos84

Try replacing ~ by $HOME?

arcanis avatar Jul 29 '22 15:07 arcanis

Try replacing ~ by $HOME?

Oh actually that worked. I guess that works for osx and linux but I would have to modify it potentially for windows but that does seem to love the problem I was having

mikematos84 avatar Jul 29 '22 18:07 mikematos84

I guess that works for osx and linux but I would have to modify it potentially for windows

Yarn uses its own portable shell to execute scripts so it works on all platforms.

merceyz avatar Jul 29 '22 20:07 merceyz

For the syntax, but I'm don't think $HOME is exposed on Windows, as we don't normalize the environment yet (would be easy to fix, though) πŸ€”

arcanis avatar Jul 29 '22 20:07 arcanis

Yea I wrote a script for my project using os.homedir() in place of $HOME since that is available on node cross-os so for now I have fixed that solution. It's just weird because if I revert to any version of yarn 1, ~ works without a problem even when its executed from a package.json script

mikematos84 avatar Jul 29 '22 20:07 mikematos84

$HOME or ~ will work on WSL + Windows or git bash or Powershell on Windows. I don't think there are many folks out there running it on bare windows terminal (cmd.exe) so I think this is an acceptable compromise.

Yarn uses its own portable shell to execute scripts so it works on all platforms.

Are there more docs on this one? Is this shell bash/zsh/??sh/posix?

mrchief avatar Jul 29 '22 21:07 mrchief