Search code examples
lernamonorepo

Lerna. Is there a command to install devDependency only in root?


According to this comment,

Indeed, devDependencies in the root package.json can be used in all packages in the monorepo. This is generally used to co-locate test-related deps and config (jest, eslint, etc).

A couple caveats:

This only works for non-CLI devDependencies. If you need to run a CLI from a child package, that CLI needs to be in that package's devDependencies. (transpiling, flowcopy, etc) All dependencies for a given child package still need to be listed in that child's package.json. (obvious, perhaps? just clarifying)

I see that devDependency in the root directory can be used for all packages. However, I can't see an obvious way to install devDependency only in root. Is there a such command or should I simply use npm/yarn -D install to do this? (or manually modify package.json)


Solution

  • If you use Yarn Workspaces, you can hoist shared dependencies in the root node_modules. To install dependencies in the root workspace, use the -W flag.

    yarn add jest --dev -W
    

    As you mentioned, these can now be used in any package.

    Source