Skip to content

Lerna seems to be losing --scope directory context in 8.1.9? #4118

@kerryj89

Description

@kerryj89

Current Behavior

After updating from 8.1.8 to 8.1.9, I am running into issues where my scripts seem to lose context of where it was ran from. Basically, I now have to explicitly provide cwd to my node scripts now as it seems Lerna process always tries to resolve from the root of the repo where my lerna.json exists.

// packages/package-a/scripts/whatever.js

// Lerna v8.1.9 no longer looks for files in context of the --scope option (seems to always want to resolve from root), so we have to let the script know about this
const workspaceRoot = path.resolve(__dirname, '../../../');

// In previous versions I did not have to pass in cwd arg
...
exec(`lerna ls --loglevel=silly --no-private --all --graph`,
            { shell: '/bin/bash', cwd: workspaceRoot },
...

I wasn't sure if this was a bug or a fix for a longstanding bug that now has to be handled more explicitly. However, I am running into another issue that might stem from the same vein that I feel more confidently is a bug.

Expected Behavior

Paths resolve like they used to prior to 8.1.9, Lerna commands not always assuming we are at the root.

Steps to Reproduce

In any lerna monorepo:

  1. npm install lerna@8.1.9
  2. npx lerna -v <- Should point to 8.1.9 just to be sure
  3. cd packages/<any-package>
  4. npx lerna list
>npx lerna list
(node:9835) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
lerna notice cli v8.1.9
lerna ERR! ENOLERNA `lerna.json` does not exist, have you run `lerna init`?

However, try it on lerna@8.1.8 and below and you will not get an error. It seems like it's always trying to resolve from the root

  1. npm install lerna@8.1.8
  2. npx lerna -v <- Should point to 8.1.8 just to be sure
  3. cd packages/<any-package>
  4. npx lerna list
>npx lerna list
(node:10692) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
lerna notice cli v8.1.8
@company/package-a
@company/package-b
@company/package-c
@company/package-d
lerna success found 4 packages

👆 Is what I'd expect, that it doesn't assume every lerna command context is from root and subsequently failing by not finding lerna.json.

Failure Logs / Configuration

lerna.json

{
  "$schema": "node_modules/lerna/schemas/lerna-schema.json",
  "npmClient": "yarn",
  "version": "0.0.0",
  "packages": [
    "packages/*"
  ],
  "command": {
    "version": {
      "conventionalCommits": true,
      "tagVersionPrefix": "",
      "message": "chore(release): Publish [skip ci]",
      "changelogPreset": {
        "name": "conventional-changelog-conventionalcommits",
        "issueUrlFormat": "https://app.clickup.com/t/{{id}}",
        "issuePrefixes": ["CU-", "cu-"],
        "commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commits/{{hash}}",
        "compareUrlFormat": "{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}"
      },
      "ignoreChanges": ["**/*.md"]
    }
  },
  "useNx": false
}

Environment

lerna notice cli v8.1.9

 Environment info:

  System:
    OS: macOS 15.0.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 22.11.0 - ~/.nvm/versions/node/v22.11.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.9.0/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v22.11.0/bin/npm
  Utilities:
    Git: 2.43.0 - /usr/local/bin/git
  npmPackages:
    lerna: ^8.1.8 => 8.1.9 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions