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

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

Closed
vhpoet opened this issue Mar 1, 2024 · 3 comments
Closed

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

vhpoet opened this issue Mar 1, 2024 · 3 comments

Comments

@vhpoet
Copy link

vhpoet commented Mar 1, 2024

I'm on "@inquirer/prompts": "^4.1.0".

My code is

import { confirm } from '@inquirer/prompts';
const confirmation = await confirm({ message: 'Are you sure?' });

I get an exception

/.../node_modules/wrap-ansi/index.js:2
const stringWidth = require('string-width');
                    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/string-width/index.js from /.../node_modules/wrap-ansi/index.js not supported.
Instead change the require of /.../node_modules/string-width/index.js in /.../node_modules/wrap-ansi/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/.../node_modules/wrap-ansi/index.js:2:21) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v21.1.0
@SBoudrias
Copy link
Owner

Hey @vhpoet, could you provide some more informations. I don't see how a new version of string-width would've gotten in your codebase through Inquirer (reviewing bumps and changes, I don't see changes around those packages versions who're pinned to cjs versions...)

The easiest would be to run either of those commands and report the output:

npm ls string-width
npm ls wrap-ansi

# or
yarn why string-width
yarn why wrap-ansi

@SBoudrias
Copy link
Owner

I'll close this issue since no answer and no one else reported an issue.

Feel free to answer and I'll reopen if we receive more information.

@vhpoet
Copy link
Author

vhpoet commented Mar 16, 2024

@SBoudrias yup, nevermind, this was caused by another package depending on the newer version.

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

No branches or pull requests

2 participants