docusaurus: Yarn PNP and TypeScript doesn't compile out of the box
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I’m using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand 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
yarn set version berrynpx create-docusaurus@latest carsync-help classic --typescriptyarn 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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 34 (8 by maintainers)
Of note, there’s work on progress to integrate PnP with rspack; I’ll report back when that changes.
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.
@alamothe No; please compile with
"moduleResolution": "NodeNext". We are using package.jsonexportsfield. Even better, consider using"skipLibCheck": true(which should be enabled by default in the latest shared tsconfig).It worked 🎉 Thanks for the help 😁
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) 🤔
Iirc the npm semver calculator uses a very old version of the semver package, with some different results.
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.@Josh-Cena Seems like we missed this spot when adding PnP support to TS, I’ll make an issue on our side to address thatNo actually scratch that, I tried in the wrong repo, it seems to work fine, sorry 😅I see - I got the wrong version due to your versioning scheme: you published a
2.0.0-beta.ff31de0ffin August, which per semver rules is higher than^2.0.0-beta.14, so that’s the version which got installed 🤔