-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Comments
Yes, I also encountered this in my project ( |
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 |
There's indeed a docusaurus/packages/docusaurus-types/src/index.d.ts Lines 75 to 86 in fb7e98a
This is the deeply partial version of |
I see - I got the wrong version due to your versioning scheme: you published a |
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? |
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 🤔 |
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 |
Same here, I used |
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 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 |
There aren't (very short discussion here, there are a few other threads). At the moment the best option would be to use
|
Yeah, the reason why I deleted my comment🤦♂️Didn't bump my SDK version so the resolver was failing |
Hey,
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? 🤷♂️ |
@slorber I can't figure out how that tool's supposed to be used... Here's what I tried: |
Iirc the npm semver calculator uses a very old version of the semver package, with some different results. |
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 |
Just deprecate all versions greater than |
This command seems to have worked:
Tell me if this improves anything Should I run this on all packages, or core would be enough? |
I got tricked by this too 😅🔫. See cloud-annotations/docusaurus-openapi/issues/150. |
@slorber I'm not sure if deprecating is enough. It seems like
|
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) 🤔 |
Nevermind, I think the deprecation works as expected. Installing However, when installing other docusaurus packages alongside @slorber So deprecating all the other old packages should fix the issue :) |
Does that happen to be because of bad lock file? |
No, I think this is the expected behavior |
I see, so what was the solution to unlock this? Regenerate the whole lockfile? |
What worked for our particular scenario was adding a bunch of resolutions and re-running "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 |
Thanks @bourdakos1 Just deprecated all the packages, let me know if you are able to remove those resolutions Hope I didn't break anything 🤪 |
It worked 🎉 Thanks for the help 😁 |
I've done some work in #7521 and fixed all missing dependency problems. However when running
When I go into |
You can try running the following command and see if it gives you some more details. PNP_DEBUG_LEVEL=1 yarn tsc |
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/[email protected]":
dependencies:
"@algolia/client-search": "4.14.2"
"@algolia/[email protected]":
peerDependencies:
"@algolia/client-search": "*"
"@algolia/autocomplete-preset-algolia": "*" But the rest are just typos, correct? Please fix. |
@alamothe No; please compile with |
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. |
Of note, there's work on progress to integrate PnP with rspack; I'll report back when that changes. |
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 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": "*" |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.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
These are all dependencies that are missing or not properly declared.
Steps to reproduce
yarn set version berry
npx create-docusaurus@latest carsync-help classic --typescript
yarn tsc
Expected behavior
Compiles without errors.
Actual behavior
Compilation errors reported:
Your environment
Reproducible demo
No response
Self-service
The text was updated successfully, but these errors were encountered: