Repository navigation
Closed
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Description
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.
Reacted by Abraham Schilling
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Activity
[-][2.0] Yarn PNP and TypeScript[/-][+][2.0] Yarn PNP and TypeScript doesn't compile out of the box[/+]Josh-Cena commentedon Dec 22, 2021
Yes, I also encountered this in my project (
@docusaurus/typesmissing 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 commentedon 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
Configtype in@docusaurus/types, referenced in the generateddocusaurus.config.js(there is aDocusaurusConfigtype, but it contains a few extra fields that the template doesn't list).Josh-Cena commentedon Dec 22, 2021
There's indeed a
Configtype here:https://github.com/facebook/docusaurus/blob/fb7e98a3456983d0e5e2ae4d408f6c2dd1b2653c/packages/docusaurus-types/src/index.d.ts#L75-L86
This is the deeply partial version of
DocusaurusConfigbefore any validation / normalizationarcanis commentedon Dec 22, 2021
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 🤔Josh-Cena commentedon Dec 22, 2021
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?
[-][2.0] Yarn PNP and TypeScript doesn't compile out of the box[/-][+]Yarn PNP and TypeScript doesn't compile out of the box[/+]arcanis commentedon 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 commentedon 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
@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 lernaalamothe commentedon Dec 23, 2021
Same here, I used
^2.0.0-beta.14and got the wrong version, then almost posted on Yarn discord about it.alamothe commentedon 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/peerDependenciesfor 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 commentedon Dec 23, 2021
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 😅11 remaining items
bourdakos1 commentedon Jan 9, 2022
Nevermind, I think the deprecation works as expected. Installing
"@docusaurus/core": "^2.0.0-beta.14"on its own, installs2.0.0-beta.14.However, when installing other docusaurus packages alongside
@docusaurus/core(say@docusaurus/preset-classic), that will install@docusaurus/[email protected], which depends on@docusaurus/[email protected]@slorber So deprecating all the other old packages should fix the issue :)
Josh-Cena commentedon Jan 9, 2022
Does that happen to be because of bad lock file?
bourdakos1 commentedon Jan 9, 2022
No, I think this is the expected behavior
slorber commentedon Jan 12, 2022
I see, so what was the solution to unlock this? Regenerate the whole lockfile?
bourdakos1 commentedon Jan 12, 2022
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:I think deprecating the rest of the canary releases for all other Docusaurus packages would remove the need for the resolutions
slorber commentedon 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 commentedon Jan 13, 2022
It worked 🎉 Thanks for the help 😁
Josh-Cena commentedon May 28, 2022
I've done some work in #7521 and fixed all missing dependency problems. However when running
tscI still get a few errors, which seem cryptic to me: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 thatRenderPropshas correct types, just thattsccannot resolve it somehow.merceyz commentedon May 28, 2022
You can try running the following command and see if it gives you some more details.
alamothe commentedon Aug 11, 2022
This is what I'm getting with the latest version:
I can fix algolia:
But the rest are just typos, correct? Please fix.
Josh-Cena commentedon Aug 12, 2022
@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).slorber commentedon 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.
arcanis commentedon Nov 7, 2024
Of note, there's work on progress to integrate PnP with rspack; I'll report back when that changes.
slorber commentedon 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_modulesI find it hard to troubleshoot duplicate packages (for examplereactor@docusaurus/theme-commonbeing used twice, leading to hooks errors). I can see withyarn whythat 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: