-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: "resolutions" trumps --ignore-optional
#6040
Comments
I was able to reproduce this problem. If It's not clear on what the expected behavior is for optional dependencies specified in |
The same for me with yarn |
I hit this problem too, and agree that this behavior is unexpected. Is there even a workaround? |
Took some time to start digging into this. Trying to understand exactly how resolutions works, but it looks like this line https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js#L286 makes a This happens before the actual dependencies are matched to resolutions, so the above line can't just be altered to match the actual dependency's I haven't found the exact spot yet, but I'm guessing that at some point it's taking the If anyone has time to jump in and help, it would be appreciated... |
Would like to take a try. |
yarnpkg/yarn#6040 Version resolutions reverse the optional'ness of a dependency. Workaround is the install with the resolution on a compatible environment then remove the resolution.
I think I found a possible workaround (that may work in some cases - worked for me with chokidar and fsevents) - install with the package's version resolution on a compatible environment. Then remove the resolution and yarn install again. Commit all that. The only problem with this is needing to redo the resolution from time to time. |
@joscha I have similar problem. Did you find any good work around for it? |
I did not unfortunately, sorry. |
I suspect it has something to do with line 289, where yarn/src/cli/commands/install.js Lines 287 to 291 in ee7b6c6
This behavior was introduced by @kaylie-alexa (committed by @arcanis) in #4105. Perhaps one of them can shed some light on how to proceed with allowing |
So I looked into the issue, and the real problem is that the deduping function is grouping the two dependency types together if their semver ranges match. So for example if you have
you'll notice that the --ignore-optional flag will work as intended. I'll look into an actual fix, but that'd be the temporary workaround. |
@kaylie-alexa I started looking at this, too. Maybe we can compare notes. Here's where I'm at:
Basically, I'm just:
With this {
"name": "yarn_testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"optionalDependencies": {
"left-pad": "^1.3.0"
},
"author": "",
"license": "ISC",
"dependencies": {
"right-pad": "^1.0.1"
},
"resolutions": {
"left-pad": "^1.3.0"
}
} FixEnsure resolutions do not conflict with optional dependencies I was able to verify that HoistManifest {
isDirectRequire: true,
isRequired: true,
isIncompatible: false,
loc: '/home/olingern/.cache/yarn/v4/npm-left-pad-1.3.0-5b8a3a7765dfe001261dde915589e782f8c94d1e/node_modules/left-pad',
pkg: [Object],
key: 'left-pad',
parts: [Array],
originalKey: 'left-pad',
previousPaths: [],
history: [Array],
isNohoist: false,
originalParentPath: '',
shallowPaths: [],
isShallow: false,
nohoistList: null } ],
Digging into Getting to it was tricky, but with some pain I tracked it down:
Some debugging output for good measures around this line. Here's the debug code I used: console.log("\n")
console.log("--------------------------------------")
console.log(pattern + " isRequired --> " + isRequired)
console.log("--------------------------------------")
console.log("ref.optional \t\t | \t" + ref.optional);
console.log("this.ignoreOptional \t | \t" + this.ignoreOptional);
console.log("isDirectRequire \t | \t" + isDirectRequire);
console.log("!ref.ignore \t\t | \t" + !ref.ignore);
console.log("!isIncompatible \t | \t" + !ref.ignore);
console.log("!isMarkedAsOptional \t | \t" + !isMarkedAsOptional); No resolutions:
With resolutions:
Eventually, I arrived back at exactly where @coreyward points out that this could be a problem. It's due to actually returning two entries of the same package, one optional and one not. return {
requests: [...resolutionDeps, ...deps],
patterns,
manifest,
usedPatterns,
ignorePatterns,
workspaceLayout,
}; If we log what is being returned here, we'll find this:
PRI opened #7272 as a place to talk about the implementation. |
Thanks so much for sleuthing @olingern! You're right resolutions shouldn't always default to being optional. I posted a PR to address the issue. |
When was this released? I just encountered this behavior with fsevents and yarn 1.22.4 |
Took a look at the fix and it looks like the 'checking for if it's marked as optional' is happening at the same package, not looking at the fully resolved subdependencies' packages optional status Any of you thumbs-uppers from the comment above (march 24th) in the same situation as us? |
@seanmakesgames Sadly yes, I get the error with yarn 1.22.5 on windows using the configuration below, unless I specifiy
|
Workaround for yarnpkg/yarn#6040 (comment)
Workaround for yarnpkg/yarn#6040 (comment)
Workaround for yarnpkg/yarn#6040 (comment)
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Currently, when there are resolutions defined,
--ignore-optional
is ignored and the optional dependencies are installed anyway.You can test it with a simple package.json:
on
yarn install --ignore-optional
the above will lead to fsevents being installed nonetheless.On Linux (Ubuntu Xenial) for example, this would fail the yarn install due to:
yarn install --ignore-optional
works as expected with:and does not install
fsevents
.What is the expected behavior?
No optional dependencies to be installed with
--ignore-optional
, no matter whether they are mentioned inresolutions
or not.Please mention your node.js, yarn and operating system version.
yarn 1.7.0
Node 10.5.0
OSX High Sierra and Debian Xenial
The text was updated successfully, but these errors were encountered: