Skip to content

fix(resolve-extends): add import attribute for JSON config files#4551

Merged
escapedcat merged 2 commits intoconventional-changelog:masterfrom
macieklamberski:master
Sep 30, 2025
Merged

fix(resolve-extends): add import attribute for JSON config files#4551
escapedcat merged 2 commits intoconventional-changelog:masterfrom
macieklamberski:master

Conversation

@macieklamberski
Copy link
Copy Markdown
Contributor

Description

Fixes ERR_IMPORT_ATTRIBUTE_MISSING error when extending JSON configuration files in Node.js ESM environments. This issue prevents users from using JSON-based commitlint configurations that extend other configs.

I had this problem recently, also found an existing issue #3970 reporting the same problem.

Modified the dynamicImport function in @commitlint/resolve-extends to detect JSON files and add the appropriate import attribute syntax based on the Node.js version:

  • Node.js < 22: Uses { assert: { type: "json" } } (import assertion syntax)
  • Node.js >= 22: Uses { with: { type: "json" } } (import attribute syntax)

This ensures backward compatibility across all supported Node.js versions while using the correct syntax for each version. The distinction is important because:

  • Import assertions (assert) were the initial implementation available in Node.js 16.15+
  • Import attributes (with) became the standard and replaced assertions in Node.js 22+
  • Node.js 22 removed support for the old assert syntax entirely

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

Motivation and Context

When trying to extend a JSON configuration file, Node.js throws ERR_IMPORT_ATTRIBUTE_MISSING because JSON imports in ESM require import attributes to specify the module type. This affects commitlint v19+ when working with JSON config files.

Closes #3970

How Has This Been Tested?

Before Fix (Error Case)

  1. Clone reproduction repository: https://github.com/macieklamberski/commitlint-json
  2. Install commitlint with npm install
  3. Run echo "feat: add something" | npx commitlint
  4. Observe ERR_IMPORT_ATTRIBUTE_MISSING error ❌

After Fix (Working Case)

  1. Clone the fix from: https://github.com/macieklamberski/commitlint

  2. Build the packages: npm install && npm run build

  3. Link the updated packages:

    cd commitlint/@commitlint/resolve-extends && npm link
    cd ../load && npm link
  4. In the cloned example project (https://github.com/macieklamberski/commitlint-json):

    npm link @commitlint/resolve-extends
    npm link @commitlint/load
  5. Run commitlint with JSON config - no error occurs ✅

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Sep 25, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@escapedcat escapedcat requested a review from JounQin September 26, 2025 08:27
Copy link
Copy Markdown
Collaborator

@JounQin JounQin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes seem reasonable while I'd prefer using require() for json files personally instead of checking Node versions.

@macieklamberski
Copy link
Copy Markdown
Contributor Author

@JounQin I have replaced previous solution with require().

@escapedcat escapedcat merged commit 82936c9 into conventional-changelog:master Sep 30, 2025
21 of 22 checks passed
immxmmi pushed a commit to immxmmi/gitea-helm-actions that referenced this pull request Apr 20, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [commitlint/commitlint](https://github.com/conventional-changelog/commitlint) | container | major | `19.9.1` -> `20.1.0` |

---

### Release Notes

<details>
<summary>conventional-changelog/commitlint (commitlint/commitlint)</summary>

### [`v20.1.0`](https://github.com/conventional-changelog/commitlint/blob/HEAD/CHANGELOG.md#2010-2025-09-30)

[Compare Source](conventional-changelog/commitlint@v20.0.0...v20.1.0)

##### Bug Fixes

- **resolve-extends:** add import attribute for JSON config files ([#&#8203;4551](conventional-changelog/commitlint#4551)) ([82936c9](conventional-changelog/commitlint@82936c9))

##### Features

- **config-pnpm-scopes:** allow global scope ([#&#8203;4553](conventional-changelog/commitlint#4553)) ([e571970](conventional-changelog/commitlint@e571970))

### [`v20.0.0`](https://github.com/conventional-changelog/commitlint/blob/HEAD/CHANGELOG.md#2000-2025-09-25)

[Compare Source](conventional-changelog/commitlint@v19.9.1...v20.0.0)

##### Bug Fixes

- update dependency tar-fs to v3.1.1 \[security] ([#&#8203;4550](conventional-changelog/commitlint#4550)) ([273a43e](conventional-changelog/commitlint@273a43e))

- feat(rules)!: make body-max-line-length ignore lines with URLs ([#&#8203;4486](conventional-changelog/commitlint#4486)) ([2f37a88](conventional-changelog/commitlint@2f37a88)), closes [#&#8203;4486](conventional-changelog/commitlint#4486)

##### BREAKING CHANGES

- when lines contain URLs exceeding the maximum
  line length `body-max-line-length` will be ignored

#### [19.9.1](conventional-changelog/commitlint@v19.9.0...v19.9.1) (2025-08-29)

##### Bug Fixes

- add TypeScript support and configuration for pnpm scopes ([#&#8203;4544](conventional-changelog/commitlint#4544)) ([ea75778](conventional-changelog/commitlint@ea75778))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Only on Sunday and Saturday ( * * * * 0,6 ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xOC4xIiwidXBkYXRlZEluVmVyIjoiNDEuMTguMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsia2luZC9kZXBlbmRlbmN5Il19-->

Reviewed-on: https://gitea.com/gitea/helm-actions/pulls/70
Reviewed-by: DaanSelen <daanselen@noreply.gitea.com>
Co-authored-by: Renovate Bot <renovate-bot@gitea.com>
Co-committed-by: Renovate Bot <renovate-bot@gitea.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ERR_IMPORT_ASSERTION_TYPE_MISSING with json config package

3 participants