How do i recover the packages in each lerna repository after i have deleted the node_modules from the sub folders?

Viewed 472

My Repository Structure is

codebook
-packages
  -clii
  -local-api
  -local-client
-lerna.json
-package.json

I installed local api to clii and local-client to local-api but for publishing i wanted to change the name of local-api and local-client so I changed local-api to @codebook/local-api and @codebook/local-client. And ran lerna bootstrap. I was getting a npm ERR! code E404. So i deleted the node_modules in each subfolders. I thought lerna bootstrap would link the new files as well as install the packages. But it is'nt working. And now all the packages are missing from each sub repositories. I can't do a npm install in each of this repositories. What should i do to install all the packages?

1 Answers

If you are changing the package name of an internal dependency that you have already added to other packages, you need to change that package name in the dependent package.json files as well. Unfortunately I'm not aware of a way to tell lerna to migrate or "rename" a dependency in the project.

So if you changed local-api to @codebook/local-api you need to go into the package.json for clii and update local-api to @codebook/local-api as well.

That said: In my experience, lerna bootstrap is pretty buggy and 404s a lot. I do not know why. All of my issues with it were solved by using lerna for adding dependencies, and yarn workspaces to download and link dependencies. The difference being, lerna just adds to the package.json file while yarn does the downloading and symlinking work.

So the process here would be to add workspaces: ["packages/*"] to your package.json and add new deps via the following commands:

lerna add @codebook/local-api --scope=clii --no-bootstrap
yarn install
Related