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

lerna publish from-package failed #3935

Open
wqcstrong opened this issue Jan 11, 2024 · 2 comments
Open

lerna publish from-package failed #3935

wqcstrong opened this issue Jan 11, 2024 · 2 comments

Comments

@wqcstrong
Copy link

Current Behavior

➜  page-spy git:(main) lerna version preminor    
lerna notice cli v8.0.2
lerna info versioning independent
lerna info Looking for changed packages since v1.5.7
lerna info version Skipping unversioned private package undefined

Changes:
 - @huolala-tech/page-spy-browser: 1.5.5 => 1.6.0-beta.0
 - @huolala-tech/page-spy-types: 1.5.5 => 1.6.0-beta.0
 - @huolala-tech/page-spy-wechat: 1.5.5 => 1.6.0-beta.0

? Are you sure you want to create these versions? Yes
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished

➜  page-spy git:(main) lerna publish from-package
lerna notice cli v8.0.2
lerna info versioning independent
lerna ERR! TypeError: Cannot read properties of undefined (reading '0')
lerna ERR!     at npa (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/node_modules/npm-package-arg/lib/npa.js:33:25)
lerna ERR!     at FetcherBase.get (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/lib/fetcher.js:482:16)
lerna ERR!     at Object.packument (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/lib/index.js:18:30)
lerna ERR!     at mapper (/Users/blucas/Code/group-opensource/page-spy/node_modules/lerna/dist/index.js:9082:34)
lerna ERR!     at /Users/blucas/Code/group-opensource/page-spy/node_modules/p-map/index.js:57:28
lerna ERR! lerna Cannot read properties of undefined (reading '0')

Expected Behavior

I can publish above 3 package to npmjs.com successfully.

Failure Logs / Configuration

lerna.json

{
  "$schema": "node_modules/lerna/schemas/lerna-schema.json",
  "version": "independent",
  "npmClient": "yarn",
  "command": {
    "version": {
      "allowBranch": ["main"],
      "preid": "beta"
    }
  }
}

lerna-debug.log

txt0 silly argv {
0 silly argv   _: [ 'publish' ],
0 silly argv   composed: 'publish',
0 silly argv   lernaVersion: '8.0.2',
0 silly argv   '$0': 'node_modules/.bin/lerna',
0 silly argv   bump: 'from-package'
0 silly argv }
1 notice cli v8.0.2
2 verbose packageConfigs Resolving packages based on package.json "workspaces" configuration.
3 verbose rootPath /Users/blucas/Code/group-opensource/page-spy
4 info versioning independent
5 verbose session f0fe18ba80631c8b
6 verbose user-agent lerna/8.0.2/node@v20.10.0+x64 (darwin)
7 verbose git-describe undefined => "@huolala-tech/page-spy-browser@1.6.0-beta.0-1-gd354080"
8 silly git-describe parsed => {"lastTagName":"@huolala-tech/page-spy-browser@1.6.0-beta.0","lastVersion":"1.6.0-beta.0","refCount":"1","sha":"d354080","isDirty":false}
9 silly getProjectsWithUnpublishedPackages
10 error TypeError: Cannot read properties of undefined (reading '0')
10 error     at npa (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/node_modules/npm-package-arg/lib/npa.js:33:25)
10 error     at FetcherBase.get (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/lib/fetcher.js:482:16)
10 error     at Object.packument (/Users/blucas/Code/group-opensource/page-spy/node_modules/pacote/lib/index.js:18:30)
10 error     at mapper (/Users/blucas/Code/group-opensource/page-spy/node_modules/lerna/dist/index.js:9082:34)
10 error     at /Users/blucas/Code/group-opensource/page-spy/node_modules/p-map/index.js:57:28

Environment

 Environment info:

  System:
    OS: macOS 14.0
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Binaries:
    Node: 20.10.0 - ~/.volta/tools/image/node/20.10.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 10.2.3 - ~/.volta/tools/image/node/20.10.0/bin/npm
  Utilities:
    Git: 2.39.2 - /usr/bin/git
  npmPackages:
    lerna: ^8.0.0 => 8.0.2 
@wqcstrong
Copy link
Author

I try to run lerna publish prerelase in other test repo, and the packages be successful published!

@wqcstrong
Copy link
Author

wqcstrong commented Jan 27, 2024

If others encounter the same situation as mine, here is my solution.

What happend?

The demo file structure in my monorepo:

├── lerna.json
├── nx.json
├── package.json
├── packages
│   ├── base
│   ├── is-even
│   └── is-odd
└── yarn.lock

I only want to publish two packages, packages/is-even and packages/is-odd. The packages/base directory contains utility functions and is not intended to be published as a package. Therefore, I have set packages/base as private:

// packages/base/package.json
{
  "private": true,
  "description": "Base utils"
}

Another necessary content occur the issue which should know is "workspaces" in my root package.json:

// package.json
{
  "name": "root",
  "private": true,
  "workspaces": [
    "packages/*"
  ],
  "dependencies": {},
  "devDependencies": {
    "lerna": "^8.0.0",
    "nx": "17.2.8"
  }
}

Deep dive

Well, I thought lerna would filter and exclude packages/base first because they are private. Indeed, lerna does do that, but before excluding them, lerna also reads private packages to obtain metadata information. This is because packages/base matches the definition in the root package.json under workspaces: ["packages/*"]. During the metadata reading process, lerna reads the "name" property of sub-packages, and since packages/base does not define a "name," it leads to the occurrence of this issue.

Solutions

  • option 1: add "name" property in packages/base, or
  • option 2: update workspaces: ["packages/is-*"] in root package.json;

After the update, lerna publish from-package works properly! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant