release-it / conventional-changelog

Conventional changelog plugin for release-it
MIT License
128 stars 38 forks source link

Error in version 7.0.1: `createPreset` is not a function. #70

Open eagerestwolf opened 1 year ago

eagerestwolf commented 1 year ago

Version 7.0.1 of this plugin has a bug that prevents release-it from running at all. When running release-it (presumably in the after:bump hook where this plugin should be running) an error will be thrown, saying that createPreset is not a function. This error exists on my local machine as well as Girhub Actions. I know the issue is this plugin because release-it was working correctly until this plugin was installed. For reference, I have included the package.json, .release-it.json, and release workflow yaml from one of my projects, as well as the output from release-it

package.json

{
  "name": "@garavest/prettier-config",
  "version": "1.0.0",
  "description": "This package contains Garavest LLC's prettier config, used for internal and shared projects.",
  "keywords": [
    "prettier",
    "config",
    "svelte",
    "tailwindcss"
  ],
  "repository": {
    "type": "git",
    "url": "git+https://github.com/garavest/prettier-config.git"
  },
  "license": "MIT",
  "author": {
    "name": "Seth Murphy",
    "email": "seth.murphy@garavest.com",
    "url": "https://garavest.com"
  },
  "type": "module",
  "main": "index.js",
  "scripts": {
    "lint": "npm run lint:code && npm run lint:format",
    "lint:code": "eslint .",
    "lint:format": "prettier -c .",
    "release": "release-it"
  },
  "dependencies": {
    "prettier": "^3.0.1",
    "prettier-plugin-svelte": "^3.0.3",
    "prettier-plugin-tailwindcss": "^0.5.3"
  },
  "devDependencies": {
    "@commitlint/cli": "^17.6.7",
    "@commitlint/config-conventional": "^17.6.7",
    "@garavest/eslint-config": "^1.0.2",
    "@release-it/conventional-changelog": "^7.0.1",
    "eslint": "^8.48.0",
    "husky": "^8.0.3",
    "lint-staged": "^14.0.1",
    "markdownlint": "^0.30.0",
    "markdownlint-cli": "^0.36.0",
    "release-it": "^16.1.5"
  }
}

.release-it.json

{
  "git": {
    "commitMessage": "chore: release v${version}",
    "requireBranch": "main"
  },
  "github": {
    "release": true
  },
  "hooks": {
    "before:init": ["git pull", "npm run lint"]
  },
  "npm": {
    "publish": true,
    "versionArgs": ["--allow-same-version"]
  },
  "plugins": {
    "@release-it/conventional-changelog": {
      "preset": "angular",
      "infile": "CHANGELOG.md"
    }
  },
  "publishConfig": {
    "access": "public"
  }
}

.github/workflows/release.yml

name: Release & Publish to NPM
on: workflow_dispatch
permissions:
  contents: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Setup Node 18
        uses: actions/setup-node@v3
        with:
          node-version: "18.x"
          registry-url: "https://registry.npmjs.org"
      - name: Initialize git user
        run: |
          git config --global user.email "seth.murphy@garavest.com"
          git config --global user.name "Release Workflow"
      - name: Initialize NPM config
        run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: Install the dependencies
        run: npm ci
      - name: Do the release
        run: npm run release --ci
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

release-it output

This is from Github Actions, but I get an idential error on my local machine.

Run npm run release --ci
  npm run release --ci
  shell: /usr/bin/bash -e {0}
  env:
    NPM_CONFIG_USERCONFIG: /home/runner/work/_temp/.npmrc
    NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX
    GITHUB_TOKEN: ***
    NPM_TOKEN: ***

> @garavest/prettier-config@1.0.0 release
> release-it
- git pull
✔ git pull
- npm run lint
✔ npm run lint
ERROR createPreset is not a function
Error: Process completed with exit code 1.

For the time being, I will try reverting to version 7.0.0 and just ignore the PRs from Dependabot. I mainly just wanted to bring this to your attention.

webpro commented 1 year ago

Does using "preset": { "name": "angular" } (instead of "preset": "angular") help?

eagerestwolf commented 1 year ago

It does not. The error persists. Also, I pinned npm's version to 7.0.0, and the bug is not present in that version.

prettier-config on  main [!] is 📦 v1.0.0 via  v18.17.0 took 11s
❯ npm run release -- --changelog

> @garavest/prettier-config@1.0.0 release
> release-it --changelog

✔ git pull
✔ npm run lint
WARNING Environment variable "GITHUB_TOKEN" is required for automated GitHub Releases.
WARNING Falling back to web-based GitHub Release.
ERROR createPreset is not a function
eagerestwolf commented 1 year ago

So, looking over the code, it would appear this isn't an issue with your plugin. I wonder if the issue lies with conventional-changelog? That's the only external import that would be using a preset to the best of my knowledge. Let me check out their issues.

eagerestwolf commented 1 year ago

Found it. Sorry for the comment spam. There is a bug in conventional-changelog. They had an open issue for this. Apparently, it was resolved in a later version.

https://github.com/conventional-changelog/conventional-changelog/issues/1114

webpro commented 1 year ago

If anyone could open a PR for this plugin and update the relevant (or all) dependencies that would be great!

silversonicaxel commented 1 year ago

Could this help https://github.com/release-it/conventional-changelog/pull/75 ?

webpro commented 1 year ago

Released v7.0.2, hth!

schorfES commented 1 year ago

Hi, even though we updated to the latest version 7.0.2, we are still facing this issue.

Installed deps:

my-app
└─┬ @release-it/conventional-changelog@7.0.2
  └── conventional-changelog@5.1.0

Error:

ERROR The "angular" preset does not export a function. Maybe you are using an old version of the preset. Please upgrade.
webpro commented 1 year ago

Did you go from "preset": "angular" to "preset": { "name": "angular" }?

schorfES commented 1 year ago

Yes, we did. We are using yaml, but tried both yaml and json with the name prop you've mentioned.

eagerestwolf commented 1 year ago

My setup is working fine using version 7.0.2 and the new configuration. I am using the JSON config.

https://github.com/garavest/eslint-config/blob/main/.release-it.json

On Mon, Oct 9, 2023, 2:26 PM Norman Rusch @.***> wrote:

Yes, we did. We are using yaml, but tried both yaml and json with the name prop you've mentioned.

— Reply to this email directly, view it on GitHub https://github.com/release-it/conventional-changelog/issues/70#issuecomment-1753574462, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXRIYCKTI7WUMWJDGJMGRDX6RFXBAVCNFSM6AAAAAA4LJGC5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJTGU3TINBWGI . You are receiving this because you authored the thread.Message ID: @.***>

silversonicaxel commented 1 year ago

From a small test, I also see now that in our code in the .yaml file, this code works:

plugins:
  '@release-it/conventional-changelog':
    preset:
      name: conventionalcommits

But this code fails:

plugins:
  '@release-it/conventional-changelog':
    preset:
      name: angular

returning the error ERROR The "angular" preset does not export a function. Maybe you are using an old version of the preset. Please upgrade.

schorfES commented 1 year ago

Thank you @silversonicaxel, this is exactly the issue.

mattfelten commented 1 year ago

So is the angular preset not usable anymore? I can also confirm the ERROR The "angular" preset does not export a function error and that swapping from angular to conventionalcommits does make it go away.

EDIT: I guess we're waiting on this https://github.com/conventional-changelog/commitlint/issues/3698

silversonicaxel commented 1 year ago

Hello @eagerestwolf, release https://github.com/conventional-changelog/commitlint/releases/tag/v18.4.3 should have fixed your issue!

webpro commented 9 months ago

If I understand correctly, the original issue is still not resolved, right? Unfortunately not seeing updates from relevant dependencies atm.

SuperITMan commented 2 months ago

I confirm that upgrading @commitlint/config-conventional to version ^19.5.0 fixes this issue 👍