docusaurus: Non declared dependencies throwing errors in Yarn v2 (berry)

🐛 Bug Report

Attempting to use Docusaurus v2 with Yarn v2 (berry). As soon as i run yarn build the build explodes with dependency errors from yarn v2.

Lots of peer dependencies aren’t specified and yarn v2 doesn’t know what to do.

Example error

Error: @docusaurus/core tried to access @docusaurus/plugin-content-blog, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Interesting that this doesn’t happen in yarn v1, but it seems to be due to no dependencies/peer dependencies being specified for the various docusaurus packages.

Steps to reproduce

  • Install/have yarn v2 as the package manager for project
  • Install docusaurus v2
  • run yarn build.

I’ve tried to install every dependency yarn says it can’t find, but it’s an endless process, and i still haven’t managed to get a build to work.

Basically, right now, docusaurus v2 is not compatible with yarn v2 😢

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 16 (5 by maintainers)

Most upvoted comments

@slorber this is an old issue but I just came across it.

Error: @docusaurus/core tried to access @docusaurus/mdx-loader, but it isn’t declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @docusaurus/mdx-loader

We are going to release very soon, let me know tomorrow afternoon if you still have issues with latest version, or if we can close this issue

This is a little tricky. Docusaurus v2 runs on a plugin system, so @docusaurus/core should not even know about the existence of @docusaurus/plugin-content-blog and should not declare plugin-specific stuff as its peer dependencies. Right now Docusaurus relies on @docusaurus/theme-classic’s dependencies (including @docusaurus/plugin-content-blog) to be hoisted to the root of node_modules. This assumption is usually true, so right now things just happen to work. To be really strict, users might need to declare dependencies on things like @docusaurus/plugin-content-blog explicitly to make it work with Yarn v2.