Skip to content

"require() of ES modules is not supported" when linting a commit #902

@danielway

Description

@danielway

Expected Behavior

commitlint should lint commit messages without errors.

Current Behavior

In a project whose package.json is configured as "type": "module", conventional-changelog/commitlint produces the following error:

(node:27380) Warning: require() of ES modules is not supported.
require() of [FULL PATH REDACTED]/commitlint-esm-bug-repro/commitlint.config.js from
[FULL PATH REDACTED]/commitlint-esm-bug-repro/node_modules/cosmiconfig/node_modules/import-fresh/index.js
is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which
defines all .js files in that package scope as ES modules.
Instead rename commitlint.config.js to end in .cjs, change the requiring code to use import(), or remove
"type": "module" from [FULL PATH REDACTED]/commitlint-esm-bug-repro/package.json.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

This seems related to how the underlying cosmiconfig package is loading the commitlint configuration.

Steps to Reproduce (for bugs)

Reproduction repository: https://github.com/danielway/commitlint-esm-bug-repro

  1. Clone and install the above repository
  2. Create some file, add to git, and commit the change
  3. Observe the error listed above

Your Environment

Commitlint: 8.3.5
Node: 12.14.1, 13.1.0, and 13.7.0 all exhibit this behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions