Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Running lerna commands inside individual packages in a monorepo throws error with lerna.json not exist #6602

Open
1 task
mohitpatel412 opened this issue Nov 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mohitpatel412
Copy link

mohitpatel412 commented Nov 16, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

I have a monorepo setup where if I am trying to run npx lerna run build.
There are 2 scenarios:

  1. When I try to run npx lerna run build from root level directory of my repo, it works fine (it runs build for all packages)
  2. When I navigate inside a package cd packages/package-a and try to run npx lerna run build, it does not run build for all packages. Instead, it throws error as below:

Caution

lerna notice cli v8.1.9
lerna ERR! ENOLERNA lerna.json does not exist, have you run lerna init?

I have lerna.json at root level directory only and it's contents are given below:

{
  "packages": ["packages/*"],
  "command": {
    "version": {
      "npmClientArgs": ["--legacy-peer-deps"]
    },
    "publish": {
      "ignoreChanges": ["*.md"],
      "verifyAccess": false
    }
  },
  "version": "independent"
}

Note

Note: It was working fine when I was using yarn 1.22.21 and used to run build for all packages when I used npx lerna run build inside individual package but this issue is coming after I switched to yarn 4.4.1. One more thing to add here is that if I add lerna.json inside the individual package, then it starts working. But IMO, it should work with just root level lerna.json config only as it used to work with yarn v1.22.21.

Can someone help to investigate why is this happening? Thanks

node: 18.18.0
yarn: 4.4.1
lerna: 8.1.9

To reproduce

//root level package.json
"name": "my-monorepo"
"private": true
"devDependencies": {
 "lerna": "^8.0.2",
}
"scripts": {
 "build": "npx lerna run build",
}
"workspaces": [
    "packages/*"
],
"engines": {
    "node": ">=18.18.0",
    "yarn": ">=4.4.1",
    "npm": ">=9.5.0"
},
//package-a package json (inside packages/packages-a folder)
"name": "package-a",
"dependencies": {
 "@xyz/abc": "1.0.0"
}
"scripts": {
 "build": "npx webpack",
}
//package-b package json (inside packages/packages-b folder)
"name": "package-b",
"dependencies": {
 "@xyz/def": "1.0.0"
}
"scripts": {
 "build": "npx webpack",
}

Environment

System:
 Apple M3 Pro (Sonoma 14.1)

Binaries:
 npm: 9.5.1
 node: 18.18.0
 yarn: 4.4.1
 lerna: 8.1.9

Additional context

If I already added "packages": ["packages/*"] in my root level lerna.json, then it should have worked inside individual packages also as it used to work with yarn v1.22.21

@mohitpatel412 mohitpatel412 added the bug Something isn't working label Nov 16, 2024
@noahnu
Copy link
Contributor

noahnu commented Dec 1, 2024

Don't use npx with yarn. Instead of npx command use yarn command.

For running commands across workspaces, use yarn workspaces foreach. Lerna is unnecessary here.

For publishing, I'd recommend my project https://github.com/monoweave/monoweave which is similar to lerna but is built using the yarn modern APIs. I've found lerna's yarn compatibility is so so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants