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

Can not use @commitlint/cz-commitlint as commitizen's adapter #3949

Closed
1 of 4 tasks
wangys4dev opened this issue Mar 4, 2024 · 5 comments · Fixed by #3963
Closed
1 of 4 tasks

Can not use @commitlint/cz-commitlint as commitizen's adapter #3949

wangys4dev opened this issue Mar 4, 2024 · 5 comments · Fixed by #3963

Comments

@wangys4dev
Copy link

wangys4dev commented Mar 4, 2024

Steps to Reproduce

1. setup scripts and install packages:

{
  "scripts": {
    "cz": "cz",
  },
  "devDependencies": {
    "@commitlint/cli": "^19.0.3",
    "@commitlint/config-conventional": "^19.0.3",
    "@commitlint/cz-commitlint": "^19.0.3",
    "commitizen": "^4.3.0"
  }
}

2. configs:
```jsonc
// .commitlintrc.json
{
  "extends": ["@commitlint/config-conventional"]
}
// .cz.json
{
  "path": "@commitlint/cz-commitlint"
}
  1. run pnpm cz

Current Behavior

got error

require() of ES Module C:\Users\admin\workspace\admin-template-vue\node_modules\.pnpm\@commitlint+cz-commitlint@19.0.3_@types+node@20.11.24_commitizen@4.3.0_inquirer@9.2.15_typescript@5.3.3\node_modules\@commitlint\cz-commitlint\lib\index.js from C:\Users\admin\workspace\admin-template-vue\node_modules\.pnpm\commitizen@4.3.0_@types+node@20.11.24_typescript@5.3.3\node_modules\commitizen\dist\commitizen\adapter.js not supported.
Instead change the require of index.js in C:\Users\admin\workspace\admin-template-vue\node_modules\.pnpm\commitizen@4.3.0_@types+node@20.11.24_typescript@5.3.3\node_modules\commitizen\dist\commitizen\adapter.js to a dynamic import() which is available in all CommonJS modules.
 ELIFECYCLE  Command failed with exit code 1.

Expected Behavior

Run commitizen normally

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

#3850

Context

No response

commitlint --version

@commitlint/cli@19.0.3

git --version

git version 2.44.0.windows.1

node --version

v20.11.1

@risu729
Copy link
Contributor

risu729 commented Mar 4, 2024

I also faced the same issue.
This issue may be related. commitizen/cz-cli#916

@frantic1048
Copy link
Contributor

frantic1048 commented Mar 4, 2024

Update - March 13, 2024: The workaround described below is no longer necessary. Upgrade @commitlint/cz-commitlint to version 19.1.0 or higher and it will function correctly with commitizen

Version 19.1.0 of @commitlint/cz-commitlint has added the required CJS export for commitizen.

For details, see the release notes at conventional-changelog/commitlint v19.1.0.


Workaround for ESM version of commitlint:

Create an adapter module: cz-adapter.cjs:

exports.prompter = async (inquirerIns, commit) => {
  ;(await import('@commitlint/cz-commitlint')).prompter(inquirerIns, commit)
}

In package.json:

{
  "config": {
    "commitizen": {
      "path": "./cz-adapter.cjs"
    }
  }
}

@wangys4dev
Copy link
Author

@frantic1048 Thanks, it works for me.

@barunprasad

This comment was marked as duplicate.

@CJKay CJKay mentioned this issue Mar 7, 2024
10 tasks
escapedcat pushed a commit that referenced this issue Mar 11, 2024
* feat: add CJS export for cz-commitlint

relates to: #3850 (comment)

resolves #3949

* chore: add .cts to eslintrc

* fix: workaround cts issues of vitest and typescript
@frantic1048
Copy link
Contributor

As a reminder, upgrading @commitlint/cz-commitlint to 19.1.0 eliminates the need for the adapter workaround mentioned above, and commitizen will function as usual.

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

Successfully merging a pull request may close this issue.

5 participants