yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.38k stars 2.72k forks source link

yarn --ignore-optional does not work properly #5878

Open quinn opened 6 years ago

quinn commented 6 years ago

Do you want to request a feature or report a bug? bug.

What is the current behavior? if i run yarn --ignore-optional somepackage I will get an error and unable to install somepackage if it depends on a private dependency that has been marked as optional.

If the current behavior is a bug, please provide the steps to reproduce. yarn add --ignore-optional wix-storybook-utils

What is the expected behavior? installs the package. Saves the pref so other people can install it too by running yarn install.

Please mention your node.js, yarn and operating system version. OS X, yarn 1.6.0, node v9.11.1

rally25rs commented 6 years ago

Yarn still has to be able to pull the metadata for the package to determine where it would be installed in node_modules if it were there and put it in the lockfile and get hoisting correct. This is basically the same as yarn install --prod still querying devDependencies. This is pretty much as-designed in yarn's scheme of making builds deterministic.

npm will completely ignore them, but also means npm is not deterministic (the result of an install may have different versions or hoist locations if the optional package was or wasn't available), so if this is a deal-breaker for you, you might actually want to use npm instead.

rally25rs commented 6 years ago

For reference, #3630

That issue was left open, so maybe we should with this one too. Although "fixing" it would, I think, fundamentally break deterministic builds and it unlikely to actually change.

quinn commented 6 years ago

@rally25rs i hear you on it breaking deterministic builds, thats why i think the pref should be saved per package (somehow, maybe in lock file). That way if optionals are ignored, they are ignored forever, and if the pref changes it would require dependencies to be resolved again. I think this would still preserve the goals of yarn and still allow me to install the package i want to install :)

quinn commented 6 years ago

@rally25rs so the point i'm making is that no-optional wouldn't just not install it, but completely exclude it from the build.

tmsdnl commented 6 years ago

Hi

Adding to the thread.

I'm behind a corporate firewall, experiencing a somewhat similar problem when trying to add a global package.

Executing: yarn global add pm2 || yarn global add --ignore-optional pm2

Results in: error An unexpected error occurred: "https://tgz.pm2.io/gkt-1.0.0.tgz: Request failed \"403 Forbidden\"".

Environment: OSX, Yarn 1.7.0, Node v8.11.2 (LTS)

Workaround: npm install -g pm2

quinn commented 5 years ago

Yeah, I still don't think the statement "fundamentally breaks deterministic builds" makes sense. This is an optional package, all of the software can function without this package in perpetuity. If you want to permanently exclude this optional package, there is no reason to resolve it.

jeffrson commented 5 years ago

Even if yarn tries to load metadata - in the end it shouldn't bail out with an error if it fails to do so for optional dependencies.

jd-carroll commented 4 years ago

It would be nice to find away to make this work. I have a number of private packages that are used in a mono-repo which are not published to any repository any where. They are listed in the optionalDeps in the package.json but when I try to install in my Dockerfile it fails.

I feel like running the combination yarn install --production --ignore-optional should ignore any resolution errors and just move on.

Or even better a --ignore-resolution-errors flag.

RobynLiu commented 2 years ago

Any update?

Pagebakers commented 1 year ago

It would be nice to find away to make this work. I have a number of private packages that are used in a mono-repo which are not published to any repository any where. They are listed in the optionalDeps in the package.json but when I try to install in my Dockerfile it fails.

I feel like running the combination yarn install --production --ignore-optional should ignore any resolution errors and just move on.

Or even better a --ignore-resolution-errors flag.

Would love to see this.