yarn
yarn copied to clipboard
yarn installed through brew fails while npm one works as expected
Do you want to request a feature or report a bug?
Bug report
What is the current behavior?
Running command through pm2 that uses yarn as script (installed or upgraded using brew), I get the following error:
> /usr/local/Cellar/yarn/1.2.1/bin/yarn: 2
> PREFIX="/usr/local" exec "/usr/local/Cellar/yarn/1.2.1/libexec/bin/yarn.js" "$@"
> ^^^^
> SyntaxError: Unexpected identifier
> at createScript (vm.js:80:10)
> at Object.runInThisContext(vm.js:139:10)
> at Module._compile (module.js:588:28)
> at Object.Module._extensions..js(module.js:635:10)
> at Module.load (module.js:545:32)
> at tryModuleLoad (module.js:508:12)
> at Function.Module._load(module.js:500:3)
> at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:70:21)
> at Module._compile (module.js:624:30)
> at Object.Module._extensions..js(module.js:635:10)
If yarn is installed globally through npm, no error will occur.
If the current behavior is a bug, please provide the steps to reproduce.
npm un -g yarn
brew install yarn
brew upgrade yarn # sometimes is needed
git clone https://github.com/fdionisi/yarn-pm2-failure \
&& cd yarn-pm2-failure \
&& yarn install \
&& yarn setup:start # or (globally) pm2 start pm2.json
What is the expected behavior?
As when yarn is installed through npm, is that no error will occur.
Please mention your node.js, yarn and operating system version.
Node: v8.6.0 and v8.7.0
OS: macOs 10.12.5 and 10.13
@arcanis @Daniel15 any ideas?
Hmm, from that error message, it looks like it's trying to execute a shell script as JavaScript? Can you try using yarn.js instead of yarn for the script in pm2?
When I try to use yarn.js for the pm2's script, nothing is happening: it doesn't boot any processes and no errors are shown.
I am experiencing this as well with pm2. @fdionisi were you able to resolve this?
@kyle-mccarthy I encountered this problem while working on a proof of concept for the company I'm working for, and we ended up not proceeding with that for other reasons. I suggest to just use npm i -g yarn instead of brew install yarn – if I'm correct that works just fine – even though is not the preferred method.
@fdionisi Awesome thank you this totally resolved my problem
confirmed this bug. I'm experiencing this. installing yarn through npm solved it
Confirming this to still be a problem in March 2023 with the following versions:
$ pm2 -v
5.2.2
$ brew -v
Homebrew 4.0.4
Homebrew/homebrew-core (git revision 34063307168; last commit 2023-03-04)
Homebrew/homebrew-cask (git revision 7a677f5ee6; last commit 2023-03-05)
$ which yarn
/usr/local/bin/yarn
...where /usr/local/bin/yarn is symlinked to /usr/local/Cellar/yarn/1.22.19/bin/yarn
As with the previous posters, no such problem after uninstalling brew's yarn, and installing globally via npm.
problem still happens, installing yarn by npm does not solve the issue on my m1 mac
In fact, as of April 9th, 2024, I'm seeing this issue happening, still. We've rolled over to another year, and the earlier reports were from back in 2017. Have to say..... wow. That's a long lead-time on a fix.
For what it's worth.....
In my case, the 'yarn' invocation that was failing was being started using PM2's JavaScript API create().
I found that by providing a single string with all the command line arguments for the script property provides a solution that seems (so far) to work correctly regardless of how Yarn was installed.