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

Error in semantic-release-monorepo: "Cannot read properties of undefined (reading 'map')" During Automated Publishing in Monorepo #158

Open
wojtekKrol opened this issue Jul 22, 2024 · 7 comments

Comments

@wojtekKrol
Copy link

I am trying to set up a monorepo with automated publishing of packages to both npm and GitHub Packages. My goal is to only publish packages that have been updated (detecting changes in files). I have configured my repository to use semantic-release with semantic-release-monorepo, but I am encountering errors during the release process.

This is the repository: https://github.com/paxcode-it/zodify-forms/tree/dev

Current Setup

Monorepo Structure

packages/
  - zod-to-fields/ 
    - release.config.cjs
    - package.json
  - zodify-forms/
    - release.config.cjs
    - package.json

Release Configuration (release.config.cjs) same for each package

/**
 * @type {import('semantic-release').GlobalConfig}
 */
module.exports = {
  extends: "semantic-release-monorepo",
  branches: [
    { name: "next", channel: "next", prerelease: true },
    { name: "experimental", channel: "experimental", prerelease: true },
    { name: "beta", channel: "beta", prerelease: true },
    { name: "dev", channel: "dev", prerelease: true },
  ],
  plugins: [
    ["@semantic-release/commit-analyzer", {
      preset: "conventionalcommits",
      releaseRules: [
        { breaking: true, release: "major" },
        { revert: true, release: "patch" },
        { type: "feat", release: "minor" },
        { type: "fix", release: "patch" },
        { type: "perf", release: "patch" },
        { type: "refactor", release: "patch" },
        { type: "build", release: "patch" },
        { type: "docs", release: "patch" },
        { type: "chore", release: false },
        { type: "test", release: false },
        { type: "ci", release: false },
        { type: "style", release: false },
      ],
      parserOpts: { noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"] },
    }],
    ["@semantic-release/release-notes-generator", {
      preset: "conventionalcommits",
      presetConfig: {
        types: [
          { type: "revert", section: "Reverts", hidden: false },
          { type: "feat", section: "Features", hidden: false },
          { type: "fix", section: "Bug Fixes", hidden: false },
          { type: "perf", section: "Performance improvements", hidden: false },
          { type: "refactor", section: "Refactors", hidden: false },
          { type: "build", section: "Build System", hidden: false },
          { type: "docs", section: "Documentation", hidden: false },
          { type: "chore", hidden: true },
          { type: "test", hidden: true },
          { type: "ci", hidden: true },
          { type: "style", hidden: true },
        ],
      },
      parserOpts: { noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"] },
    }],
    "@semantic-release/npm",
    "@semantic-release/github",
    ["@semantic-release/git", {
      "assets": ["package.json"],
      "message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
    }],
  ],
};

GitHub Actions CI/CD Configuration

name: CI/CD

on:
  push:
    paths:
      - 'packages/**'
    branches:
      - main
      - beta
      - next
      - experimental
      - dev
  pull_request:
    paths:
      - 'packages/**'

jobs:
  CI:
    ...

  CD:
    permissions:
      contents: write
      issues: write
      pull-requests: write
      id-token: write
    if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2
      - uses: pnpm/action-setup@v3
        with:
          version: 9
      - name: Read .nvmrc
        run: echo ::set-output name=NVMRC::$(cat .nvmrc)
        id: nvm
      - name: Setup Node.js (.nvmrc)
        uses: actions/setup-node@v4
        with:
          node-version: '${{ steps.nvm.outputs.NVMRC }}'
          cache: pnpm
          cache-dependency-path: './pnpm-lock.yaml'
      - run: pnpm install --frozen-lockfile
      - run: pnpm run build:lib
      - name: Release lib to NPM Registry and GitHub Packages
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
        run: pnpm run deploy:lib

Problem Encountered

I am encountering an error during the release process:

TypeError: Cannot read properties of undefined (reading 'map')
    at withFiles (file:///home/runner/work/zodify-forms/zodify-forms/node_modules/.pnpm/semantic-release-monorepo@8.0.2_semantic-release@24.0.0/node_modules/semantic-release-monorepo/src/only-package-commits.js:26:13)
    at onlyPackageCommits (file:///home/runner/work/zodify-forms/zodify-forms/node_modules/.pnpm/semantic-release-monorepo@8.0.2_semantic-release@24.0.0/node_modules/semantic-release-monorepo/src/only-package-commits.js:38:34)
    ...

Additionally, I received an ENOGHTOKEN error indicating no GitHub token is specified.
Full logs:https://github.com/paxcode-it/zodify-forms/actions/runs/10028361403/job/27715190158

Question

Is it possible to achieve what I want using semantic-release-monorepo? Specifically, I need to:

  1. Automatically publish only the packages that have been updated.
  2. Publish these packages to both npm and GitHub Packages.

If there are any alternative approaches or additional configurations required to achieve this, I would appreciate any guidance or examples. ( I couldn't find any open source project with those requirements)

Thank you

@juliosampaio
Copy link

I'm facing the exact same issue:

[10:07:00 AM] [semantic-release] › ✘  An error occurred while running semantic-release: TypeError: Cannot read properties of undefined (reading 'map')
    at withFiles (file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:26:13)
    at onlyPackageCommits (file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:38:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/options-transforms.js:8:58
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/lens-utils.js:7:17
    at async file:///runner/_work/acme-react-libraries/acme-react-libraries/node_modules/semantic-release-monorepo/src/only-package-commits.js:86:5 {
  pluginName: '[Function: semantic-release-monorepo]'
}

Was you able to solve that @wojtekKrol ?

@wojtekKrol
Copy link
Author

Was you able to solve that @wojtekKrol ?

Unfortunately not yet

@wojtekKrol
Copy link
Author

@juliosampaio please ping me once you resolve your problem okey?

@juliosampaio
Copy link

Hey @wojtekKrol , we actually decided to use Changesets instead, which is the opposite approach on all the automation provided by semantic-release, but fits perfectly on our use case. I'm glad we did tbh 😀

@wojtekKrol
Copy link
Author

@juliosampaio and do you have case that includes monorepo with multiple libraries published to npm/github registry?

Can you share configs?

Thanks

@dionysiusmarquis
Copy link

This seems to happen if another plugin throws an error. I had to comment out extends: “semantic-release-monorepo” to be able to see the actual error.

@pmrotule
Copy link

This seems to happen if another plugin throws an error. I had to comment out extends: “semantic-release-monorepo” to be able to see the actual error.

Oh great! Same here, thanks for pointing it out.

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

No branches or pull requests

4 participants