Skip to content
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

Yarn PNP and TypeScript doesn't compile out of the box #6157

Closed
7 tasks done
alamothe opened this issue Dec 22, 2021 · 34 comments · May be fixed by #7539
Closed
7 tasks done

Yarn PNP and TypeScript doesn't compile out of the box #6157

alamothe opened this issue Dec 22, 2021 · 34 comments · May be fixed by #7539
Labels
bug An error in the Docusaurus core causing instability or issues with its execution help wanted Asking for outside help and/or contributions to this particular issue or PR.

Comments

@alamothe
Copy link

alamothe commented Dec 22, 2021

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • 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

Yarn PNP and TypeScript doesn't compile out of the box. I had to add the following entries to .yarnrc.yml to make it work:

.yarnrc.yml
  "@docusaurus/module-type-aliases@*":
    dependencies:
      "@types/history": "*"
      "@types/react-loadable": "*"
  "@docusaurus/plugin-content-blog@*":
    peerDependencies:
      "@docusaurus/types": "*"
  "@docusaurus/plugin-content-pages@*":
    peerDependencies:
      "@docusaurus/types": "*"
  "@docusaurus/plugin-content-docs@*":
    peerDependencies:
      "@docusaurus/types": "*"
    dependencies:
      "@docusaurus/module-type-aliases": "2.0.0-beta.14"
  "@docusaurus/theme-common@*":
    peerDependencies:
      "@docusaurus/types": "*"
      "@types/react": "*"
  "@docusaurus/theme-classic@*":
    peerDependencies:
      "@docusaurus/types": "*"
    dependencies:
      "utility-types": "*"
  "@docusaurus/preset-classic@*":
    peerDependencies:
      "@docusaurus/types": "*"
    dependencies:
      "@docusaurus/theme-common": "2.0.0-beta.14"
  "@docusaurus/mdx-loader@*":
    dependencies:
      "unified": "*"
  "@docusaurus/utils@*":
    peerDependencies:
      "@docusaurus/types": "*"

These are all dependencies that are missing or not properly declared.

Steps to reproduce

  1. yarn set version berry
  2. npx create-docusaurus@latest carsync-help classic --typescript
  3. yarn tsc

Expected behavior

Compiles without errors.

Actual behavior

Compilation errors reported:
../.yarn/__virtual__/@docusaurus-mdx-loader-virtual-adf7a41f60/0/cache/@docusaurus-mdx-loader-npm-2.0.0-beta.14-971ea241f9-248a8f73b4.zip/node_modules/@docusaurus/mdx-loader/src/mdx-loader.d.ts:8:27 - error TS2307: Cannot find module 'unified' or its corresponding type declarations.

8 import type {Plugin} from 'unified';
                            ~~~~~~~~~

../.yarn/__virtual__/@docusaurus-plugin-content-blog-virtual-e96af830a4/0/cache/@docusaurus-plugin-content-blog-npm-2.0.0-beta.14-3465a1b1cb-9d98707faa.zip/node_modules/@docusaurus/plugin-content-blog/src/plugin-content-blog.d.ts:29:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

29   import type {TOCItem} from '@docusaurus/types';
                                ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-plugin-content-docs-virtual-f0cdf7992e/0/cache/@docusaurus-plugin-content-docs-npm-2.0.0-beta.14-5f7a4ed55b-d7c1951f18.zip/node_modules/@docusaurus/plugin-content-docs/src/plugin-content-docs.d.ts:81:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

81   import type {TOCItem} from '@docusaurus/types';
                                ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-plugin-content-docs-virtual-f0cdf7992e/0/cache/@docusaurus-plugin-content-docs-npm-2.0.0-beta.14-5f7a4ed55b-d7c1951f18.zip/node_modules/@docusaurus/plugin-content-docs/src/types.ts:8:23 - error TS2688: Cannot find type definition file for '@docusaurus/module-type-aliases'.

8 /// <reference types="@docusaurus/module-type-aliases" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-plugin-content-pages-virtual-dbf42224e5/0/cache/@docusaurus-plugin-content-pages-npm-2.0.0-beta.14-0bbd113bd5-1372f554d8.zip/node_modules/@docusaurus/plugin-content-pages/src/plugin-content-pages.d.ts:13:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

13   import type {TOCItem} from '@docusaurus/types';
                                ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-preset-classic-virtual-ab54b4a240/0/cache/@docusaurus-preset-classic-npm-2.0.0-beta.14-c882f4954f-67019820c8.zip/node_modules/@docusaurus/preset-classic/src/preset-classic.d.ts:19:34 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

19 export type ThemeConfig = import('@docusaurus/types').ThemeConfig &
                                    ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-preset-classic-virtual-ab54b4a240/0/cache/@docusaurus-preset-classic-npm-2.0.0-beta.14-c882f4954f-67019820c8.zip/node_modules/@docusaurus/preset-classic/src/preset-classic.d.ts:20:10 - error TS2307: Cannot find module '@docusaurus/theme-common' or its corresponding type declarations.

20   import('@docusaurus/theme-common').UserThemeConfig & {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-ec17751a11/0/cache/@docusaurus-theme-classic-npm-2.0.0-beta.14-ecbe2a9dfe-ebb4c362e4.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:602:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

602   import type {TOCItem} from '@docusaurus/types';
                                 ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-ec17751a11/0/cache/@docusaurus-theme-classic-npm-2.0.0-beta.14-ecbe2a9dfe-ebb4c362e4.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:617:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

617   import type {TOCItem} from '@docusaurus/types';
                                 ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-ec17751a11/0/cache/@docusaurus-theme-classic-npm-2.0.0-beta.14-ecbe2a9dfe-ebb4c362e4.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:642:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

642   import type {TOCItem} from '@docusaurus/types';
                                 ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-ec17751a11/0/cache/@docusaurus-theme-classic-npm-2.0.0-beta.14-ecbe2a9dfe-ebb4c362e4.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:655:30 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

655   import type {TOCItem} from '@docusaurus/types';
                                 ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-ec17751a11/0/cache/@docusaurus-theme-classic-npm-2.0.0-beta.14-ecbe2a9dfe-ebb4c362e4.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:809:31 - error TS2307: Cannot find module 'utility-types' or its corresponding type declarations.

809   import type {Optional} from 'utility-types';
                                  ~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-58b8d3e7b7/0/cache/@docusaurus-theme-common-npm-2.0.0-beta.14-de796828fc-dbe969d676.zip/node_modules/@docusaurus/theme-common/lib/utils/historyUtils.d.ts:7:15 - error TS2305: Module '"@docusaurus/history"' has no exported member 'Location'.

7 import type { Location, Action } from '@docusaurus/history';
                ~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-58b8d3e7b7/0/cache/@docusaurus-theme-common-npm-2.0.0-beta.14-de796828fc-dbe969d676.zip/node_modules/@docusaurus/theme-common/lib/utils/historyUtils.d.ts:7:25 - error TS2305: Module '"@docusaurus/history"' has no exported member 'Action'.

7 import type { Location, Action } from '@docusaurus/history';
                          ~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-58b8d3e7b7/0/cache/@docusaurus-theme-common-npm-2.0.0-beta.14-de796828fc-dbe969d676.zip/node_modules/@docusaurus/theme-common/lib/utils/tocUtils.d.ts:7:25 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

7 import { TOCItem } from '@docusaurus/types';
                          ~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-58b8d3e7b7/0/cache/@docusaurus-theme-common-npm-2.0.0-beta.14-de796828fc-dbe969d676.zip/node_modules/@docusaurus/theme-common/lib/utils/useLocationChange.d.ts:7:10 - error TS2305: Module '"@docusaurus/history"' has no exported member 'Location'.

7 import { Location } from '@docusaurus/history';
           ~~~~~~~~

../.yarn/__virtual__/@docusaurus-utils-virtual-064bf14a46/0/cache/@docusaurus-utils-npm-2.0.0-beta.14-d4176db19a-f527eeeca5.zip/node_modules/@docusaurus/utils/lib/index.d.ts:7:76 - error TS2307: Cannot find module '@docusaurus/types' or its corresponding type declarations.

7 import { ReportingSeverity, TranslationFileContent, TranslationFile } from '@docusaurus/types';
                                                                             ~~~~~~~~~~~~~~~~~~~

../.yarn/cache/@docusaurus-module-type-aliases-npm-2.0.0-beta.14-2a8c7bc4e7-d4bb46da11.zip/node_modules/@docusaurus/module-type-aliases/src/index.d.ts:99:44 - error TS2307: Cannot find module 'react-loadable' or its corresponding type declarations.

99   import type {LoadingComponentProps} from 'react-loadable';
                                              ~~~~~~~~~~~~~~~~

../.yarn/cache/@docusaurus-module-type-aliases-npm-2.0.0-beta.14-2a8c7bc4e7-d4bb46da11.zip/node_modules/@docusaurus/module-type-aliases/src/index.d.ts:233:17 - error TS2307: Cannot find module 'history' or its corresponding type declarations.

233   export * from 'history';
                    ~~~~~~~~~

../.yarn/cache/@docusaurus-module-type-aliases-npm-2.0.0-beta.14-2a8c7bc4e7-d4bb46da11.zip/node_modules/@docusaurus/module-type-aliases/src/index.d.ts:275:29 - error TS2307: Cannot find module 'react-loadable' or its corresponding type declarations.

275   import type Loadable from 'react-loadable';
                                ~~~~~~~~~~~~~~~~


Found 20 errors.

Your environment

  • Docusaurus version used: 2.0.0-beta.14

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.
@alamothe alamothe added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Dec 22, 2021
@alamothe alamothe changed the title [2.0] Yarn PNP and TypeScript [2.0] Yarn PNP and TypeScript doesn't compile out of the box Dec 22, 2021
@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Dec 22, 2021
@Josh-Cena
Copy link
Collaborator

Yes, I also encountered this in my project (@docusaurus/types missing as dependency). However I also don't want to include these type-only packages as production dependency because I assume that's not the usual practice. @merceyz What would be a good middleground? Should we actually declare dependency on types packages because our exported types rely on them?

@arcanis
Copy link
Contributor

arcanis commented Dec 22, 2021

They should be added in the template, as development dependency, since they are referenced in the generated config file.

Also note that I think there might be a mistake in the template, as I don't see a Config type in @docusaurus/types, referenced in the generated docusaurus.config.js (there is a DocusaurusConfig type, but it contains a few extra fields that the template doesn't list).

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Dec 22, 2021

There's indeed a Config type here:

// Docusaurus config, as provided by the user (partial/unnormalized)
// This type is used to provide type-safety / IDE auto-complete on the config file
// See https://docusaurus.io/docs/typescript-support
export type Config = Overwrite<
Partial<DocusaurusConfig>,
{
title: Required<DocusaurusConfig['title']>;
url: Required<DocusaurusConfig['url']>;
baseUrl: Required<DocusaurusConfig['baseUrl']>;
i18n?: DeepPartial<DocusaurusConfig['i18n']>;
}
>;

This is the deeply partial version of DocusaurusConfig before any validation / normalization

@arcanis
Copy link
Contributor

arcanis commented Dec 22, 2021

I see - I got the wrong version due to your versioning scheme: you published a 2.0.0-beta.ff31de0ff in August, which per semver rules is higher than ^2.0.0-beta.14, so that's the version which got installed 🤔

@Josh-Cena
Copy link
Collaborator

Haha, we have another person who got tricked... See also #6140. It seems to be only caused when migrating to PnP though? Time to clear up my doubt: does Yarn take timestamps into account when resolving versions?

@Josh-Cena Josh-Cena changed the title [2.0] Yarn PNP and TypeScript doesn't compile out of the box Yarn PNP and TypeScript doesn't compile out of the box Dec 22, 2021
@arcanis
Copy link
Contributor

arcanis commented Dec 22, 2021

It's not PnP, just the regular Yarn resolution. We take all the versions, filter the compatible ones, and get the max satisfying one. Because semver is weird, it can be problematic with things like this ...

Other package managers (including Yarn 1.x) perhaps don't sort the versions returned by the registry, but we do since semver resolution isn't supposed to be order-dependent 🤔

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Dec 22, 2021

Yeah, we have ~150 beta canary version names that could be messing with semver, wondering if we should deprecate them all.

Bad releases
2.0.0-beta.2c0b82e7a
2.0.0-beta.8e9b829d9
2.0.0-beta.22d3299b4
2.0.0-beta.bb825faf1
2.0.0-beta.bd46de18f
2.0.0-beta.8a198ef20
2.0.0-beta.650f989db
2.0.0-beta.9e615eff0
2.0.0-beta.fc64c12e4
2.0.0-beta.4bc6a6375
2.0.0-beta.c935fe2a3
2.0.0-beta.bb0c9eed0
2.0.0-beta.b3e89d2a8
2.0.0-beta.4cfbfa11e
2.0.0-beta.ce847d664
2.0.0-beta.a72ed73d2
2.0.0-beta.a7618c775
2.0.0-beta.dc4664b48
2.0.0-beta.798f63400
2.0.0-beta.938e5a906
2.0.0-beta.6f366f4b4
2.0.0-beta.8621ae291
2.0.0-beta.a7a5ea346
2.0.0-beta.083037d7a
2.0.0-beta.24156efcf
2.0.0-beta.700a82aef
2.0.0-beta.ddc0f46b7
2.0.0-beta.4d06f26c1
2.0.0-beta.12cea5eef
2.0.0-beta.88de3a510
2.0.0-beta.44225a3df
2.0.0-beta.54e4b0266
2.0.0-beta.633c2f60d
2.0.0-beta.f7b5e9039
2.0.0-beta.8bdb3da23
2.0.0-beta.0851e0e5b
2.0.0-beta.818fb3956
2.0.0-beta.007e90135
2.0.0-beta.677e53d4d
2.0.0-beta.d3764f77f
2.0.0-beta.f33cd079c
2.0.0-beta.fa9b0cd9c
2.0.0-beta.12faed89d
2.0.0-beta.45a87a147
2.0.0-beta.0fdb6836a
2.0.0-beta.1a3557b91
2.0.0-beta.be695aa0e
2.0.0-beta.3e5a83259
2.0.0-beta.7babfe036
2.0.0-beta.9536ef900
2.0.0-beta.f03479f69
2.0.0-beta.dc9f104cc
2.0.0-beta.7b2723717
2.0.0-beta.0acbbc3d3
2.0.0-beta.f316ff5cd
2.0.0-beta.237d1a31f
2.0.0-beta.fbdeefcac
2.0.0-beta.d65cc9d23
2.0.0-beta.15a2b59f9
2.0.0-beta.1ec2c95e3
2.0.0-beta.823b020c3
2.0.0-beta.c3127b65d
2.0.0-beta.0f144213d
2.0.0-beta.ab3821cb3
2.0.0-beta.1cecd78f2
2.0.0-beta.e5916dc59
2.0.0-beta.a78e4f19b
2.0.0-beta.7fe2a9891
2.0.0-beta.759298296
2.0.0-beta.41b78466d
2.0.0-beta.79031af16
2.0.0-beta.4d93c894f
2.0.0-beta.67d31f49e
2.0.0-beta.ec2486d2c
2.0.0-beta.138b4c997
2.0.0-beta.05c85c7be
2.0.0-beta.462b1cf2b
2.0.0-beta.364051f23
2.0.0-beta.f47826297
2.0.0-beta.aa79387e1
2.0.0-beta.99270dbab
2.0.0-beta.9916a0b4a
2.0.0-beta.7e55aa10a
2.0.0-beta.119c6d143
2.0.0-beta.4e88ea0a1
2.0.0-beta.8bda3b2db
2.0.0-beta.41eaa690e
2.0.0-beta.f20599bb5
2.0.0-beta.9fdbd4827
2.0.0-beta.8d8e5b67e
2.0.0-beta.7dc9fe839
2.0.0-beta.0e652730d
2.0.0-beta.ba6545057
2.0.0-beta.1b0acc554
2.0.0-beta.b54ec7238
2.0.0-beta.80b6d9728
2.0.0-beta.0bbbfb641
2.0.0-beta.4a6de5cf7
2.0.0-beta.aa176274b
2.0.0-beta.32e76f1cc
2.0.0-beta.41d9288e3
2.0.0-beta.8501db78a
2.0.0-beta.bfd33dc63
2.0.0-beta.af3640dca
2.0.0-beta.34411e12e
2.0.0-beta.9fe79caad
2.0.0-beta.dfe32dac9
2.0.0-beta.52f19e15f
2.0.0-beta.57cf20933
2.0.0-beta.ace285b3b
2.0.0-beta.c8b9061f6
2.0.0-beta.e2acda64f
2.0.0-beta.e25c0e7d3
2.0.0-beta.737f80a02
2.0.0-beta.aeb8e9da5
2.0.0-beta.8629fbdc7
2.0.0-beta.aff848e87
2.0.0-beta.df8a900f9
2.0.0-beta.77264f1eb
2.0.0-beta.a5d3d28ce
2.0.0-beta.a024d23fd
2.0.0-beta.55e9bd8ac
2.0.0-beta.d81d43c24
2.0.0-beta.869f4bf20
2.0.0-beta.d0bbdd053
2.0.0-beta.f71e83450
2.0.0-beta.526ce4493
2.0.0-beta.df19bbd14
2.0.0-beta.2303d6557
2.0.0-beta.ce0764033
2.0.0-beta.f10304dd1
2.0.0-beta.57806798c
2.0.0-beta.85e87b560
2.0.0-beta.1349ece88
2.0.0-beta.a1c17c76e
2.0.0-beta.35bdde340
2.0.0-beta.0417ab953
2.0.0-beta.d72f760e4
2.0.0-beta.644f148a8
2.0.0-beta.d2e4e60cd
2.0.0-beta.15d451942
2.0.0-beta.35b1941a0
2.0.0-beta.1decd6f80
2.0.0-beta.dc0336a34
2.0.0-beta.a9343a191
2.0.0-beta.5bc0209f5
2.0.0-beta.ff31de0ff
2.0.0-beta.56b6b01cd
2.0.0-beta.db6f5ce72
2.0.0-beta.6392f88bb
2.0.0-beta.2cd9fd6e2
2.0.0-beta.1ab8aa0af
2.0.0-beta.e85ec1ab1
2.0.0-beta.fa7aa0810
2.0.0-beta.ab19070ab
2.0.0-beta.be9f9d6df
2.0.0-beta.b561679fd
2.0.0-beta.c0b8e9116
2.0.0-beta.73c24ecdc
2.0.0-beta.69be003e1
2.0.0-beta.e09291062
2.0.0-beta.01adf25b0

@slorber Maybe we should write a little script to deprecate all these versions? I know with Yarn you would do yarn workspaces foreach, dunno if there's something similar with lerna

@alamothe
Copy link
Author

Same here, I used ^2.0.0-beta.14 and got the wrong version, then almost posted on Yarn discord about it.

@alamothe
Copy link
Author

alamothe commented Dec 23, 2021

Going back to the issue, I am of the opinion if you export types from another package, it should be stated as a dependency, otherwise it's relying on that package being included by someone else. If not, it's essentially saying let's ignore the concept of dependencies/peerDependencies for types altogether.

The downside is that if the user does not care about TypeScript and uses plain JavaScript, they would still get this dependency. Perhaps there should be a concept of typeDependency?

@arcanis
Copy link
Contributor

arcanis commented Dec 23, 2021

The downside is that if the user does not care about TypeScript and uses plain JavaScript, they would still get this dependency. Perhaps there should be a concept of typeDependency?

There aren't (very short discussion here, there are a few other threads). At the moment the best option would be to use peerDependencies, and let package managers implement @types pruning.

Also, it seems like "extends": "@tsconfig/docusaurus/tsconfig.json", doesn't work in PnP? Does Yarn have custom resolver support for this?

@Josh-Cena Seems like we missed this spot when adding PnP support to TS, I'll make an issue on our side to address that No actually scratch that, I tried in the wrong repo, it seems to work fine, sorry 😅

@Josh-Cena
Copy link
Collaborator

Yeah, the reason why I deleted my comment🤦‍♂️Didn't bump my SDK version so the resolver was failing

@Josh-Cena Josh-Cena added the help wanted Asking for outside help and/or contributions to this particular issue or PR. label Dec 25, 2021
@slorber
Copy link
Collaborator

slorber commented Dec 29, 2021

Hey,

I used ^2.0.0-beta.14 and got the wrong version

According to this tool https://semver.npmjs.com/ there's only one version that matches. Isn't Yarn supposed to implement the exact same rules? 🤷‍♂️

@Josh-Cena
Copy link
Collaborator

@slorber I can't figure out how that tool's supposed to be used... Here's what I tried:

image

@arcanis
Copy link
Contributor

arcanis commented Dec 29, 2021

Iirc the npm semver calculator uses a very old version of the semver package, with some different results.

@slorber
Copy link
Collaborator

slorber commented Dec 29, 2021

Yes, I'm not very confident with these range things.

Looking at how to deprecate all those legacy canary releases, not sure what's the best way.

Executing npm deprecate commands one by one for all versions/packages is going to take forever.

It takes a range, but will it actually work for our use-case? I might as well deprecate all betas and then undeprecate the few betas we want to keep 🤷‍♂️ or use the npm API directly

@Josh-Cena
Copy link
Collaborator

Just deprecate all versions greater than beta.10000 then :D

@slorber
Copy link
Collaborator

slorber commented Dec 29, 2021

This command seems to have worked:

npm deprecate @docusaurus/core@">= 2.0.0-beta" "deprecated canary release, please upgrade"

npm deprecate @docusaurus/core@"2.0.0-beta.0 || 2.0.0-beta.1 || 2.0.0-beta.2 || 2.0.0-beta.3 || 2.0.0-beta.4 || 2.0.0-beta.5 || 2.0.0-beta.6 || 2.0.0-beta.7 || 2.0.0-beta.8 || 2.0.0-beta.9 || 2.0.0-beta.10 || 2.0.0-beta.11 || 2.0.0-beta.12 || 2.0.0-beta.13 || 2.0.0-beta.14" ""

Tell me if this improves anything

Should I run this on all packages, or core would be enough?

@JaimeObregon
Copy link

I got tricked by this too 😅🔫. See cloud-annotations/docusaurus-openapi/issues/150.

@bourdakos1
Copy link

@slorber I'm not sure if deprecating is enough. It seems like @docusaurus/core@npm:2.0.0-beta.fc64c12e4 is deprecated, but yarn 3.1.1 still installs it (we use "^2.0.0-beta.14" for all docusaurus package versions):

@docusaurus/core@npm:2.0.0-beta.fc64c12e4 is deprecated: deprecated canary release, please upgrade

@arcanis
Copy link
Contributor

arcanis commented Jan 8, 2022

I'll check tomorrow, but we're supposed to prioritize non-deprecated releases if there's any matching the requested range (failing that, we pick a deprecated one) 🤔

@bourdakos1
Copy link

Nevermind, I think the deprecation works as expected. Installing "@docusaurus/core": "^2.0.0-beta.14" on its own, installs 2.0.0-beta.14.

However, when installing other docusaurus packages alongside @docusaurus/core (say @docusaurus/preset-classic), that will install @docusaurus/preset-classic@2.0.0-beta.fc64c12e4, which depends on @docusaurus/core@2.0.0-beta.fc64c12e4

@slorber So deprecating all the other old packages should fix the issue :)

@Josh-Cena
Copy link
Collaborator

will install @docusaurus/preset-classic@2.0.0-beta.fc64c12e4, which depends on @docusaurus/core@2.0.0-beta.fc64c12e4

Does that happen to be because of bad lock file?

@bourdakos1
Copy link

No, I think this is the expected behavior

@slorber
Copy link
Collaborator

slorber commented Jan 12, 2022

I see, so what was the solution to unlock this? Regenerate the whole lockfile?

@bourdakos1
Copy link

What worked for our particular scenario was adding a bunch of resolutions and re-running yarn install, no need to delete yarn.lock or anything:

"resolutions": {
  "@docusaurus/core": "2.0.0-beta.14",
  "@docusaurus/preset-classic": "2.0.0-beta.14",
  "@docusaurus/mdx-loader": "2.0.0-beta.14",
  "@docusaurus/plugin-content-docs": "2.0.0-beta.14",
  "@docusaurus/types": "2.0.0-beta.14",
  "@docusaurus/utils-validation": "2.0.0-beta.14",
  "@docusaurus/utils": "2.0.0-beta.14"
}

I think deprecating the rest of the canary releases for all other Docusaurus packages would remove the need for the resolutions

@slorber
Copy link
Collaborator

slorber commented Jan 13, 2022

Thanks @bourdakos1

Just deprecated all the packages, let me know if you are able to remove those resolutions

Hope I didn't break anything 🤪

@bourdakos1
Copy link

It worked 🎉 Thanks for the help 😁

@Josh-Cena
Copy link
Collaborator

I've done some work in #7521 and fixed all missing dependency problems. However when running tsc I still get a few errors, which seem cryptic to me:

.yarn/__virtual__/@docusaurus-theme-classic-virtual-59c6f4f552/0/cache/@docusaurus-theme-classic-npm-0.0.0-5076-a80de9154f-0c8b55566c.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:218:35 - error TS2339: Property 'getLineProps' does not exist on type '{}'.

218   type GetLineProps = RenderProps['getLineProps'];
                                      ~~~~~~~~~~~~~~

.yarn/__virtual__/@docusaurus-theme-classic-virtual-59c6f4f552/0/cache/@docusaurus-theme-classic-npm-0.0.0-5076-a80de9154f-0c8b55566c.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:219:36 - error TS2339: Property 'getTokenProps' does not exist on type '{}'.

219   type GetTokenProps = RenderProps['getTokenProps'];
                                       ~~~~~~~~~~~~~~~

.yarn/__virtual__/@docusaurus-theme-classic-virtual-59c6f4f552/0/cache/@docusaurus-theme-classic-npm-0.0.0-5076-a80de9154f-0c8b55566c.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:220:28 - error TS2339: Property 'tokens' does not exist on type '{}'.

220   type Token = RenderProps['tokens'][number][number];
                               ~~~~~~~~

.yarn/cache/unified-npm-9.2.2-65676eec78-7c24461be7.zip/node_modules/unified/types/ts4.0/index.d.ts:3:20 - error TS2307: Cannot find module 'unist' or its corresponding type declarations.

3 import {Node} from 'unist'
                     ~~~~~~~

When I go into .yarn/__virtual__/@docusaurus-theme-classic-virtual-59c6f4f552/0/cache/@docusaurus-theme-classic-npm-0.0.0-5076-a80de9154f-0c8b55566c.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts, I can see that RenderProps has correct types, just that tsc cannot resolve it somehow.

@merceyz
Copy link
Contributor

merceyz commented May 28, 2022

You can try running the following command and see if it gives you some more details.

PNP_DEBUG_LEVEL=1 yarn tsc

@alamothe
Copy link
Author

alamothe commented Aug 11, 2022

This is what I'm getting with the latest version:

../.yarn/__virtual__/@docsearch-react-virtual-d0cb4410d8/0/cache/@docsearch-react-npm-3.2.0-6c2ef6865a-219c15259c.zip/node_modules/@docsearch/react/dist/esm/DocSearch.d.ts:2:36 - error TS2307: Cannot find module '@algolia/client-search' or its corresponding type declarations.

2 import type { SearchOptions } from '@algolia/client-search';
                                     ~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-1475f1f307/0/cache/@docusaurus-theme-classic-npm-2.0.1-dbd0568bd1-f37077f394.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:1150:44 - error TS2307: Cannot find module '@docusaurus/theme-common/Details' or its corresponding type declarations.

1150   import {Details, type DetailsProps} from '@docusaurus/theme-common/Details';
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-classic-virtual-1475f1f307/0/cache/@docusaurus-theme-classic-npm-2.0.1-dbd0568bd1-f37077f394.zip/node_modules/@docusaurus/theme-classic/src/theme-classic.d.ts:1172:34 - error TS2307: Cannot find module '@docusaurus/theme-common/internal' or its corresponding type declarations.

1172   import type {TOCTreeNode} from '@docusaurus/theme-common/internal';
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-a8ce414b90/0/cache/@docusaurus-theme-common-npm-2.0.1-73566d28ef-65261e6f77.zip/node_modules/@docusaurus/theme-common/lib/contexts/docsPreferredVersion.d.ts:8:36 - error TS2307: Cannot find module '@docusaurus/plugin-content-docs/client' or its corresponding type declarations.

8 import { type GlobalVersion } from '@docusaurus/plugin-content-docs/client';
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/__virtual__/@docusaurus-theme-common-virtual-a8ce414b90/0/cache/@docusaurus-theme-common-npm-2.0.1-73566d28ef-65261e6f77.zip/node_modules/@docusaurus/theme-common/lib/utils/docsUtils.d.ts:8:72 - error TS2307: Cannot find module '@docusaurus/plugin-content-docs/client' or its corresponding type declarations.

8 import { type GlobalVersion, type GlobalSidebar, type GlobalDoc } from '@docusaurus/plugin-content-docs/client';
                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/cache/@algolia-autocomplete-core-npm-1.7.1-488e460895-511176e9c2.zip/node_modules/@algolia/autocomplete-core/dist/esm/types/AutocompleteSource.d.ts:1:43 - error TS2307: Cannot find module '@algolia/autocomplete-preset-algolia' or its corresponding type declarations.

1 import type { RequesterDescription } from '@algolia/autocomplete-preset-algolia';
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/cache/@algolia-autocomplete-core-npm-1.7.1-488e460895-511176e9c2.zip/node_modules/@algolia/autocomplete-core/dist/esm/utils/mapToAlgoliaResponse.d.ts:1:67 - error TS2307: Cannot find module '@algolia/client-search' or its corresponding type declarations.

1 import type { SearchForFacetValuesResponse, SearchResponse } from '@algolia/client-search';
                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~

../.yarn/cache/@algolia-autocomplete-core-npm-1.7.1-488e460895-511176e9c2.zip/node_modules/@algolia/autocomplete-core/dist/esm/utils/mapToAlgoliaResponse.d.ts:4:18 - error TS2307: Cannot find module '@algolia/client-search' or its corresponding type declarations.

4     hits: import("@algolia/client-search").Hit<THit>[][];
                   ~~~~~~~~~~~~~~~~~~~~~~~~

I can fix algolia:

  "@docsearch/react@3.2.0":
    dependencies:
      "@algolia/client-search": "4.14.2"
  "@algolia/autocomplete-core@1.7.1":
    peerDependencies:
      "@algolia/client-search": "*"
      "@algolia/autocomplete-preset-algolia": "*"

But the rest are just typos, correct? Please fix.

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Aug 12, 2022

@alamothe No; please compile with "moduleResolution": "NodeNext". We are using package.json exports field. Even better, consider using "skipLibCheck": true (which should be enabled by default in the latest shared tsconfig).

@slorber
Copy link
Collaborator

slorber commented Nov 7, 2024

This is an old issue and we have been able to enable Yarn PnP in our CI e2e tests so that our init template can at least work using it:

https://github.com/facebook/docusaurus/blob/main/.github/workflows/tests-e2e.yml#L75

It's working (and we'll try to keep it this way)


But to be honest I wouldn't recommend using Yarn PnP with Docusaurus. It might work for some, but whenever I have to troubleshoot an open-source site using it, it's really time-consuming for me to try to troubleshoot things that otherwise work with the node linker, and is a real time sink.

Just a few examples:

It's hard and time-consuming for me to ensure that all things work properly under both linkers, unfortunately. If you adopt PnP, please consider that you might have to figure out problems on your own. I can only commit to making a basic Docusaurus site work under PnP, but can't ensure that all third-party plugins, libs, and packages will work well using it.

@slorber slorber closed this as completed Nov 7, 2024
@arcanis
Copy link
Contributor

arcanis commented Nov 7, 2024

Of note, there's work on progress to integrate PnP with rspack; I'll report back when that changes.

@slorber
Copy link
Collaborator

slorber commented Nov 7, 2024

Great news thanks!

I'd be happy if we could improve PnP support, but I lack good troubleshooting skills for Yarn PnP.

Since I can't inspect node_modules I find it hard to troubleshoot duplicate packages (for example react or @docusaurus/theme-common being used twice, leading to hooks errors). I can see with yarn why that there's some kind of duplicate used though (different hash/ids?) but don't know why.

I also struggle to understand how to deal with optional peer dependencies, which our v3.6 Docusaurus faster project rely on extensively. On a site upgrade using PnP (easyops-cn/docusaurus-search-local#468) I figured out we had to declare a few extra dependencies for packages that are not always in our control and also using optional peer dependencies:

packageExtensions:
  "@docusaurus/bundler@*":
    dependencies:
      "@docusaurus/faster": "*"
  "@docusaurus/theme-common@*":
    dependencies:
      "@docusaurus/plugin-content-docs": "*"
  "terser-webpack-plugin@*":
    dependencies:
      "@swc/core": "*"
  "css-minimizer-webpack-plugin@*":
    dependencies:
      "lightningcss": "*"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution help wanted Asking for outside help and/or contributions to this particular issue or PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants