yarnpkg/yarn

TypeError: Reduce of empty array with no initial value

spalger opened this issue Β· 28 comments

What is the current behavior? Installing dependencies fails with error An unexpected error occurred: "Reduce of empty array with no initial value".

If the current behavior is a bug, please provide the steps to reproduce.

This is the simplest reproduction I've been able to create. The result should look something like this: https://github.com/spalger/reproduce-issues/tree/master/yarn-reduce-of-empty-array-without-initial-value

error log: https://github.com/spalger/reproduce-issues/blob/master/yarn-reduce-of-empty-array-without-initial-value/bar/yarn-error.log

# create two packages
mkdir foo bar

# install `tree-kill` dependency in `foo`
cd foo && yarn init -y && yarn add tree-kill

# link to `foo` from bar
cd ../bar && yarn init -y && yarn add link:../foo

yarn add in bar should fail.

What is the expected behavior? yarn add should not fail with internal error

Please mention your node.js, yarn and operating system version.
node -v: v8.11.0
yarn -v: 1.7.0

@spalger i can try to look into this tonight.

I think I've found this issue and I'll have a PR up tonight. cc @bestander

ping me when PR is ready

Thanks @bestander and @bdwain!

Any idea when this will land as a point release like 1.7.1 ? i just got bit by the link problem...

Temporary workaround until patch release (works for me): remove node_modules, install without links, then add links back.

rm -rf node_modules
yarn
yarn link myProject

I already did this (on MacOS)

$ brew unlink yarn

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/76215230de5f7f7bee2cfcdd7185cf49d949862d/Formula/yarn.rb

$ brew switch yarn 1.6.0_1

Many thanks to @nothingismagick for the workaround.

I don't understand how a bug this serious made it into a release of mission-critical software like Yarn.

Yeah, its kind of a weird situation. Over at https://github.com/quasarframework/quasar I have been championing Yarn - especially for our devs working on core. Being able to so effortlessly link (and not accidentally destroy the linked folder!!!) with yarn is a huge selling point. Telling them to downgrade makes me feel silly. :(

By the way, there are several ways to "link", and the one I currently prefer is e.g.:

yarn add "quasar-cli@link:../quasar-cli"

This way I don't have to run the link command in the quasar-cli folder and the target folder. This is nice when you need to have multiple versions and DON'T want a global link polluting your work.

Oh, thanks, I didn't know about that. (We have almost entirely managed to stop using yarn link, finding that workspaces do most of what we need.)

Perhaps Yarn shouldn't encourage people to upgrade to a new major version until it has been out a while? I only upgraded because Yarn suggested it. Now my projects are broken.

Though, I'm sure this is a rare thing that such a big feature goes haywire and it gets released that way.

Will there be a point release 1.7.1 or is 1.8.0 coming too soon?
Anyone in my team that starts with or updates to the latest stable yarn runs into this issue.

Yarn 1.8 has been released two weeks ago: https://github.com/yarnpkg/yarn/releases

I'll move it to stable tomorrow since we haven't got critical reports yet, but you can already install it from various ways (for example with npm, npm install -g yarn@rc should do the trick).

According to https://yarnpkg.com/en/docs/install#mac-rc, 1.7.0 is still the release candidate. (It's also the stable version of course.)

But yes, RC is 1.8.0 on NPM.

This is kind of silly but it's working for me

npx yarn@rc add <package>

@arcanis any update on moving yarn 1.8 to stable?

Others recommended a rm -rf node_modules and then re-yarn-install. But I just had to

yarn unlink PACKAGE
yarn
yarn link PACKAGE

I cannot install last yarn 1.8.0 from choco install yarn@1.8.0 or choco install yarn@rc - error: package did not found. Also if I try to make it throw npm install -g yarn@rc I gets installed yarn v.1.8.0 on my machine, but really, when I try to run yarn info or yarn versions - I see yarn v.1.7.0 in log. Miracle...

@arcanis thanks ! πŸ‘

as a workaround you can do (on MacOS) until 1.8.0 lands in brew

brew unlink yarn
brew install https://raw.githubusercontent.com/joscha/homebrew-core/a6f904aac4df702cfff11d94d5fd257f841bffa2/Formula/yarn.rb
mvu02 commented

@arcanis v1.7.0 is still listed as the stable version and v1.8.0 seems to have been taken off the RC list on https://yarnpkg.com/en/docs/install#windows-stable. Is there a window installer I can get for v1.8.0 somewhere?

The latest version of yarn is 1.9.2 already, just upgrade your yarn.

https://yarnpkg.com/en/package/yarn

hey i got 2 times today on bot.binary.com
using a robot error
Reduce an empty array with no initial value

72040927-bfb37c80-32b2-11ea-9ac3-c86e95b63d0a