question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`lerna create` <loc> misrecords subpackage location

See original GitHub issue

Given:

{
  "version": "0.0.0",
  "npmClient": "npm",
  "packages": [
    "apps/*",
    "libs/*"
  ]
}

When I run lerna create pkg libs/pkg, it creates the package at apps/pkg, but still points to an erroneous location. This caused https://github.com/folke/vscode-monorepo-workspace/issues/34.

I later realized I could achieve the desired effect with lerna create pkg libs, though this prevents you from easily creating a package whose name and directory are different.

Additionally, I didn’t receive an error saying the location was invalid, nor a warning indicating the package was put in the default location.

Expected Behavior

I would prefer if I run lerna create @ns/long-pack-name libs/short for the package to be placed at libs/short with name @ns/long-pack-name. And if libs/short didn’t match any package globs, I would prefer an error message.

If this doesn’t work for you, I would at least prefer an error to creating the package in a location I didn’t select.

Current Behavior

Currently, no errors are issued, the package is created in the wrong location, and the package isn’t correctly recorded, wherever that data is stored.

Context

This lerna.json is simplified from my setup—a multi-app deployment. I’m subdividing a rather big project into multiple subdirectories to streamline an infra-as-code ci/cd pipeline. I have discovered work arounds for what I need to do (lots of lerna bootstrap), but I really just want a quick way to initialize new packages.

Your Environment

Executable Version
lerna --version 3.20.2
npm --version 6.14.3
yarn --version no
node --version 13.10.1
OS Version
NAME VERSION
macOS Sierra 10.15.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:15
  • Comments:6

github_iconTop GitHub Comments

1reaction
richardantaocommented, Jun 12, 2022

It looks like the output folder will simply be the first blob in the packages array in your lerna.json.

At first, my lerna.json was simply:

{
  "packages": [
    "packages/*"
  ],
  "version": "0.0.0"
}

And packages would only get placed directly under the packages folder, regardless of what path I passed to in [loc] lerna create <name> [loc].

Then, when my lerna.json was:

{
  "packages": [
    "packages/apps/*",
    "packages/libs/*"
  ],
  "version": "0.0.0"
}

Packages would only be placed in the packages/apps folder, even when I tried to create with lerna create <package-name> ./packages/libs/<package-name>.

0reactions
JamesHenrycommented, Nov 29, 2022

Thanks for reporting this folks! We will gladly review PRs to improve this behaviour, I agree it seems to currently be unintuitive or broken in certain cases.

Additionally, I have opened an issue to track improvements to customizing lerna create more broadly here: #3444

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing Monorepo using Lerna and Yarn workspaces
For example, Yarn Workspaces create a single yarn.lock file in the root directory, and use it to manage all dependencies between multiple ...
Read more >
A Beginner's Guide to Lerna with Yarn Workspaces | by jsilvax
Flow for Creating a New Package. New packages need to be created under the packages directory. Let's create a dummy form package cd...
Read more >
Lerna — Install Dependencies for a Specific Package
Lerna comes with an add command to install NPM dependencies in your project's packages. By default, lerna adds a new dependency to all...
Read more >
Lerna not generating package-lock.json for every package
I couldn't find a concrete solution to generate lock files for all packages. I mean there are ways but, everything is increasing the ......
Read more >
How To Manage Monorepos With Lerna - DigitalOcean
In this tutorial, you will install Lerna, create a working directory, initialize a Lerna project, create a monorepo, bootstrap your packages ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found