Giter Site home page Giter Site logo

Comments (8)

snikch avatar snikch commented on April 27, 2024 1

Thanks @slorber. Neither of those options helped, but I'll look into this deeper when I have time. We're in a "good enough" state for now. I appreciate your help so far ❤️ .

from docusaurus.

slorber avatar slorber commented on April 27, 2024

Docusaurus docs are transpiled by MDX to React components.
This also means that some dependencies must be found in a parent node_module folder of the docs, otherwise those "MDX React components" do not find the appropriate dependencies.

The key thing to understand is that your docs are like React code, and the appropriate dependencies must be available to them.

This usually works fine with most monorepo tools, because they would hoist the dependencies at the top of your monorepo node_modules, but won't work with Yarn PnP system.

Yarn 2+ uses a Plug and Play mode by default, which behaves a bit differently than traditional monorepo tools, and is "stricter"

You can use any of those solutions to fix the problem under Yarn 2+:

Disable PnP mode:

yarn config set nodeLinker node-modules
yarn install
yarn workspace docs start

Hoist the dependencies at monorepo root yourself

yarn add @mdx-js/react@npm:3.0.1 react@npm:18.2.0
yarn workspace docs start

Unfortunately it's hard for us to make Docusaurus work out of the box with all monorepo tools and fancy setups users might attempt to use, but the general idea remains that the appropriate dependencies should be available to docs, no matter how those dependencies get wired.

from docusaurus.

snikch avatar snikch commented on April 27, 2024

@slorber thank you for your quick and detailed reply. Hoisting the imports to the root has some difficulties but we've managed to get a "good enough" version working.

We've lost things like prism code syntax highlighting and admonitions. I assume this is likely the same issue and I need to hoist a variety of other packages. I tried with these but it still didn't seem to work. Does anything come to mind?

yarn add @docusaurus/preset-classic @docusaurus/plugin-content-docs @docusaurus/core prism-react-renderer

from docusaurus.

slorber avatar slorber commented on April 27, 2024

To be honest I don't really have any expertise in Yarn PnP system and don't use it myself 😅

I remember it was challenging to get our e2e tests pass under PnP but it's mostly @Josh-Cena that fixed those as far as I remember.

Afaik there are several options you can try, such as:

from docusaurus.

slorber avatar slorber commented on April 27, 2024

Great 👍

Maybe @arcanis could help you, he's using Docusaurus on the Yarn website and probably knows how to handle this situation better than I do 😄

from docusaurus.

snikch avatar snikch commented on April 27, 2024

Nice, keen to hear more on how people have solved / worked around this!

I guess it might make sense to add a little more info on the reasoning for including docs outside the actual docusaurus website. I run two docs websites which document a monorepo using Yarn workspaces. In both cases I actually want to include documentation directly from the package README's.

e.g. a monorepo structured like this;

├── apps
│   ├── app.xxx.com
│   ├── contributors.xxx.com <- 🦖
│   └── graphql.xxx.com
└── packages
     ├── cli
     ├── db-app
     ├── email
     ├── graphql
     ├── log
     ├── otel
     ├── services
     └── ui

in my docusaurus navigation I have a main menu item of "packages" which then contains the documentation for each individual package. I find this pattern works really well as it allows us to keep the README's as the central documentation for each package.

from docusaurus.

oliveirarafa avatar oliveirarafa commented on April 27, 2024

I'm using npm workspaces with nx and i'm facing a similar problem.

I can't import a react component library to use on the live editor, but if I take my site outside the monorepo it works.

from docusaurus.

slorber avatar slorber commented on April 27, 2024

@oliveirarafa this issue is about Yarn PnP and not related to the live editor. What you encounter is probably unrelated and we'd need a minimal https://docusaurus.new/stackblitz repro to investigate as a separate issue.

from docusaurus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.