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

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

Closed
1 of 4 tasks
alexcloudstar opened this issue Jan 5, 2024 · 12 comments · Fixed by #3850
Closed
1 of 4 tasks

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

alexcloudstar opened this issue Jan 5, 2024 · 12 comments · Fixed by #3850

Comments

@alexcloudstar
Copy link

alexcloudstar commented Jan 5, 2024

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/cli@18.4.4
└─┬ yargs@17.7.2
└── cliui@8.0.1

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

@escapedcat
Copy link
Member

Can you create a minimal repo for reproduction?

I know you tried node v18, but just fyi: only even versions are the real production ones

@alexcloudstar
Copy link
Author

Hi @escapedcat , thank you for your response. Sure, here's the repo
https://github.com/alexcloudstar/commit-lint-es-module-error

@escapedcat
Copy link
Member

escapedcat commented Jan 5, 2024

Thanks, yeah, weird.
After the first install I got the same issue.
After doing this the test ran fine.

yarn test
yarn run v1.22.21
warning package.json: No license field
$ jest
 PASS  app/Button.test.tsx
  Button
    ✓ renders Button component (13 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.481 s, estimated 1 s
Ran all test suites.
✨  Done in 1.84s.

node -v
v18.19.0

Not sure why this is happening tbh.

@alexcloudstar
Copy link
Author

alexcloudstar commented Jan 5, 2024

Thanks, yeah, weird.

After the first install I got the same issue.

After doing this the test ran fine.

yarn test

yarn run v1.22.21

warning package.json: No license field

$ jest

 PASS  app/Button.test.tsx

  Button

    ✓ renders Button component (13 ms)



Test Suites: 1 passed, 1 total

Tests:       1 passed, 1 total

Snapshots:   0 total

Time:        0.481 s, estimated 1 s

Ran all test suites.

✨  Done in 1.84s.



node -v

v18.19.0

Not sure why this is happening tbh.

Yea.. that is what i observed as well. But, i cannot do these in Ci/CD every time. Plus, if you delete node_modules and then try to run yarn install --frozen-lockfile you will get same issue every time

@escapedcat
Copy link
Member

True, not sure how to fix this.

@alexcloudstar
Copy link
Author

Thanks for the help anyway. Maybe someone from the community had the same issue and solved somehow.

@escapedcat
Copy link
Member

Yeah, if this happens more often, people will at least find this issue. Thanks for raising!

@art1373
Copy link

art1373 commented Jan 8, 2024

It also happens for me, upgrading from 18.4.3 ❯ 18.4.4

@escapedcat
Copy link
Member

Hm, which change could have caused this?
v18.4.3...v18.4.4

@alexcloudstar
Copy link
Author

No one has a fix? Not even maintainers? 😢

@escapedcat
Copy link
Member

Does this duplicate or relate to #3642?

@JounQin
Copy link
Contributor

JounQin commented Jan 11, 2024

Does this duplicate or relate to #3642?

Yes, same thing.

@JounQin JounQin mentioned this issue Jan 12, 2024
10 tasks
coreboot-org-bot pushed a commit to coreboot/arm-trusted-firmware that referenced this issue Mar 8, 2024
Commitizen is currently generating errors due to ES Module/CommonJS
incompatibilities described by the following GitHub issue:

    conventional-changelog/commitlint#3842

This change implements the temporary workaround described by the issue.

Change-Id: Idb74a3366bf046a0c9bac83380de904c5c059087
Signed-off-by: Chris Kay <chris.kay@arm.com>
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.

4 participants