facebook / facebook/docusaurus

Conflicting versions when using canary releases + third-party plugins

未关闭
#7,728 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
bug external
主要语言
TypeScript
星标
66.2k
派生
10k
平均合并
1 天 3 小时
30 天内合并 PR
52

描述

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#reporting-new-issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [ ] I have tried creating a repro with https://new.docusaurus.io.
- [ ] I have read the console error message carefully (if applicable).

### Description

Let's imagine you are using a canary release of Docusaurus, and also a third-party plugin.

You likely have this in your package.json file:

```
"@docusaurus/core": "0.0.0-5170",
"@docusaurus/preset-classic": "0.0.0-5170",
"@easyops-cn/docusaurus-search-local": "^0.28.0",
```

Problem: `@easyops-cn/docusaurus-search-local` depends on many Docusaurus core packages with semver range `^2.0.0-beta.20`, and `^2.0.0` does not match `0.0.0`

This potentially leads to duplicate core package installs in your repo, and multiple versions of the same package being used at runtime.

This is particularly problematic for packages exporting React providers because contexts are now duplicated, leading to weird issues like this one https://github.com/facebook/docusaurus/issues/7686#issuecomment-1172377776

A workaround is to use things like npm/yarn resolutions so that the user forces the package manager to duplicate packages.

We'll probably move `@docusaurus/theme-common` to peerDependency in the future, as it's the package most likely to cause troubles (exporting many React contexts)

Another possibility is to change another time the canary versioning scheme, maybe using `3.0.0-something` for the canaries after we release 2.0? This should be changed carefully, as this scheme has been the source of troubles in the past, see https://github.com/facebook/docusaurus/pull/5295)

### Reproducible demo

_No response_

### Steps to reproduce

see https://github.com/facebook/docusaurus/issues/7686#issuecomment-1172377776

### Expected behavior

Use canary + third-party plugin without duplicated packages and weird React context issues

### Actual behavior

see https://github.com/facebook/docusaurus/issues/7686#issuecomment-1172377776: unexpected React context issues

### Your environment

- Public source code:
- Public site URL:
- Docusaurus version used:
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):

### Self-service

- [ ] I'd be willing to fix this bug myself.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。