berry
berry copied to clipboard
Potential yarn 2 package.json scripts execution privileges issue
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.
Try replacing ~ by $HOME?
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
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.
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) π€
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
$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?