I have a lerna repo for a project under development. It has several packages that depend on each other. To make development easier, none of the packages are published and they depend on the latest version of each other.
Directory tree
foo/ packages/ core/ package.json errors/ package.json
foo/packages/core/package.json
{ ... dependencies: { "@foo/errors": "*" } }
I have another project, bar
, that I'm using to test the lerna project. Currently I'm linking to its dependencies using a local file:
dependency:
bar/package.json
{ ... dependencies: { "@foo/core": "../foo/packages/core" } }
This approach has given me a world of trouble.
yarn install
in bar
. Yarn follows the file:
dependency to @foo/core
, sees that it depends on @foo/errors
and doesn't know about lerna's symlink. This causes it to fail, telling me it can't find @foo/errors
.This has made writing actual code for this project secondary to this mess of dependency management.
How can I make this (I feel fairly simple?) project structure work? Open to lerna/yarn/npm/pnpm/shell scripts/MS DOS at this point.
Lerna is a fast modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
To start to use lerna you need install the package in mode global or use npx, when you decide what you need to do. Before to continue I suggest you create a branch and call it lerna-init, it will be used in the future. After that we need to init our lerna project, lerna has two modes: fixed/locked and independent.
You should be able to accomplish this with npm link
. Although I have not tried this using a local dependency that is not published on npm.
Directory tree
foo/ packages/ core/ package.json errors/ package.json bar/ package.json
foo/packages/core/package.json
{ ... dependencies: { "@foo/errors": "*" } }
bar/package.json
{ ... dependencies: { "@foo/core": "../foo/packages/core" } }
Run the following commands
cd foo npx lerna clean npx lerna bootstrap --hoist npm run build # command to build your projects cd packages/core npm link cd ../../../bar npm i npm link @foo/core
Removing package-lock.json files usually does more harm then good! And about not being able to find @foo/errors
, if you ran npm bootstrap, @foo/core
should be symlinked to @foo/errors
. One possibility could be that your lerna scripts are using npm while you where running install/link with yarn.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With