Skip to content

fix: Error [ERR_REQUIRE_ESM]: require() of ES Module #3842

Closed
@alexcloudstar

Description

@alexcloudstar

Expected Behavior

Should work i guess?

Current Behavior

Right now , when i run yarn install --frozen-lockfile and then try to test it with Jest for example, i got this issue:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/stefanalexandruromila/Projects/alexcloudstar/project_name/node_modules/string-width/index.js from /Users/stefanalexandruromila/Projects/alexcloudstar/project_name/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /Users/stefanalexandruromila/Projects/alexcloudstar/project_name/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object. (/Users/stefanalexandruromila/Projects/alexcloudstar/project_name/node_modules/cliui/build/index.cjs:291:21)

But, if I run yarn install is working fine.

I use frozen-lockfile for Docker & CI/CD pipelines

I tried also to downgrade the node version to 18. And tried to downgrade the package to a smaller version but still got the issue.

I know that is saying something about string-width & cliui. But I run npm ls string-width / cliui, i got:

@commitlint/[email protected]
└─┬ [email protected]
└── [email protected]

Also, this package is scoped to project and is NOT a global install

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Steps to Reproduce

run yarn install --frozen-lockfile

run npx jest test or npx commitlint --config .commintlintrc.cjs

Context

No response

commitlint --version

18.4.4

git --version

v2.39.3

node --version

v21.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions