nx next react and storybook

Here's a small monorepo newbie guide (2024)

I decided to write a small guide since I keep seeing DEVs getting into trouble with nx + storybook

To start off, NX js is an awesome build system tech to help you manage monorepo projects.
A monorepo is a repo with multiple apps/projects.
We usually opt for monorepos when we have multiple apps that needs to share code.

Let's say you have 1 server application and 2 client applications, the server and the clients would share api types and utilities.
the clients would also share the same system design.

this kind of monorepo would have a structure like this:

  • /server/server-1
  • /client/client-1
  • /client/client-2
  • /shared/api-clients
  • /shared/types
  • /shared/ui

try to add storybook to the ui project: https://nx.dev/nx-api/storybook nx add @nx/storybook nx g @nx/storybook:configuration ui run these commands and then choose @storybook/nextjs framework

to run storybook: npx nx storybook ui from the root directory

note that any nx command must be running from root so if you are working on ./server/server-1 you need to cd ../../ to ./