-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
This is a CLI Docs Enhancement, not another kind of Docs Enhancement.
- This is a CLI Docs Enhancement.
Description of Problem
The public documentation for the overrides
package.json key doesn't mention any limitations regarding workspaces or monorepos.
However, it seems overrides
don't work in workspace package.json
files (from my testing they only work from the root package.json
), and this appears to be by design - the RFC says:
Only Root Package May Contain Overrides
The overrides key will only be considered when it is in the root package.json file for a project. overrides in installed dependencies (including workspaces) will not be considered in dependency tree resolution. Thus, there is no cascading overrides between multiple different package.json files at any given time.
Published packages may dictate their resolutions by pinning dependencies or using an npm-shrinkwrap.json file.
Applying overrides for workspaces and installed dependencies may be considered in a future RFC. However, there are considerable challenges in the implementation, user expectations, and security of such an approach.
Most package.json keys work in both root and workspace files, so this is a specific limitation of overrides
that should be documented in the overrides
docs.
I certainly expected overrides to work in workspaces as well as the project root based on having read the documentation, and I only discovered the RFC note after browsing recent overrides-related issues and finding #4205
Potential Solution
- Add a line in the Overrides documentation saying something like:
In a monorepo with workspaces, overrides may only be defined in the project root package.json. Overrides within workspace package.json files are ignored.
- Maybe also log a warning or error on running
npm install
if a workspace's package.json has anoverrides
key, rather than the feature just failing silently? Like:
Warning:
overrides
found in workspace ${workspaceName}. Overrides may only be set in the project root.
Docs URL
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides