One repo, two packages at the workshop: what do npm workspaces put in the root’s node_modules, where does a clashing version go, and can app use a chalk it…
Why it matters
Nearly every large project is a monorepo. Knowing workspaces tells you why a sibling package imports without publishing, why there is one big node_modules at the root, why two versions can show up at once, and why something can work in the repo yet break when someone else installs it.
The key idea
A workspace is a link, and its dependencies rise to the root
Common mistakes
Forgetting to list a folder in the root’s workspaces npm links only folders that match workspaces ("packages/*" covers them all). A package in a folder not listed is looked up on the registry, hence E404, and npm run -w for it answers No workspaces found.
Thinking the workspace link ships with the packagenpm pack and npm publish pack that package’s own files only. A dependency on another workspace stays written as a range (^1.0.0) and is installed from the registry, so that package must be published too. workspace:* is pnpm’s and yarn’s (they swap it for a version when publishing); npm refuses it with EUNSUPPORTEDPROTOCOL.
Two packages ask for different versions, expecting one copy npm puts one version in the root’s node_modules and nests the other in the node_modules of the workspace that asked for it. Two copies are two modules: instanceof fails between them, state is not shared, and a doubled React gives "Invalid hook call". Align the ranges, or make it a peerDependency.
Try it in this playground
See a workspace linknode_modules/@bengkel/struk points at packages/struk.
Make two copies of chalk Ranges that do not meet: one at the root, one nested.
Run app without listing chalk It runs, thanks to struk’s chalk at the root.
Break app from struk Drop chalk from struk while app does not list it.