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

Can't run the sample #2

Open
juanwalker opened this issue Sep 13, 2022 · 8 comments
Open

Can't run the sample #2

juanwalker opened this issue Sep 13, 2022 · 8 comments
Assignees

Comments

@juanwalker
Copy link

When I run the example index.js is showing me the error:

const inquirer = require('inquirer');
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\pablo\workspace\graduados-node-js\node_modules\inquirer\lib\inquirer.js from C:\Users\pablo\workspace\graduados-node-js\node_modules\inquirer-tree-prompt\example\index.js not supported.
Instead change the require of inquirer.js in C:\Users\pablo\workspace\graduados-node-js\node_modules\inquirer-tree-prompt\example\index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\pablo\workspace\graduados-node-js\node_modules\←[4minquirer-tree-prompt←[24m\example\index.js:1:18) {
  code: ←[32m'ERR_REQUIRE_ESM'←[39m
}
@insightfuls
Copy link
Owner

Can you please let me know your Node JS and inquirer versions? npm version will show you both, if you're using npm. Either or both of these will have changed since this plugin was originally authored, and it's still working in my context, but obviously not in yours.

@insightfuls insightfuls self-assigned this Sep 14, 2022
@juanwalker
Copy link
Author

juanwalker commented Sep 14, 2022

Sure I ran the command and this is the output

C:>npm version
{
npm: '8.15.0',
node: '16.17.0',
v8: '9.4.146.26-node.22',
uv: '1.43.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.18.1',
modules: '93',
nghttp2: '1.47.0',
napi: '8',
llhttp: '6.0.7',
openssl: '1.1.1q+quic',
cldr: '41.0',
icu: '71.1',
tz: '2022a',
unicode: '14.0',
ngtcp2: '0.1.0-DEV',
nghttp3: '0.1.0-DEV'
}

@MatheusTran
Copy link

this is because Inquirer v9 and higher are native esm modules, so they don't support common js syntax. downgrade to a lower version of inquirer and that should fix your problem

@insightfuls
Copy link
Owner

Thanks for the hint @scaevitas . @juanwalker , hopefully the workaround above works for you, but I'll try to find some time to update this to be compatible with Inquirer v9+, but it could be a number of weeks before I manage it.

@juanwalker
Copy link
Author

@insightfuls @scaevitas I downgrade to 8.2.4 and I manage to render the tree with the options at first level but Im not able to see sub levels, I don't see any error in the screen from this, any guessings about what may be wrong? Thank you

image

@MatheusTran
Copy link

MatheusTran commented Sep 22, 2022

@juanwalker I downgraded to 8.0.0 (as suggested in the inquirer repository) and it worked fine

I also went into the directory of inquirer tree to downgrade it to 8.0.0, so that could be what caused it to work

@juanwalker
Copy link
Author

you are right! Im so fool I didn't use the arrows. Is working with versions lower than 9!

@tewshi
Copy link

tewshi commented Nov 10, 2022

@insightfuls , could you please update this package can be used on es6 module project?

import TreePrompt from 'inquirer-tree-prompt';

inquirer.registerPrompt('tree', TreePrompt);

When I tried it, it gives me error

const BasePrompt = require('inquirer/lib/prompts/base');
                   ^

Error [ERR_REQUIRE_ESM]: require() of ES Module F:\Git\node\args-cli\node_modules\inquirer\lib\prompts\base.js from F:\Git\node\args-cli\node_modules\inquirer-tree-prompt\index.js not supported.
Instead change the require of base.js in F:\Git\node\args-cli\node_modules\inquirer-tree-prompt\index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (F:\Git\node\args-cli\node_modules\inquirer-tree-prompt\index.js:11:20)
    at async Promise.all (index 0)
    at async file:///F:/Git/node/args-cli/src/cli.js:10:33 {
  code: 'ERR_REQUIRE_ESM'
}

I use node@16.13.0 and npm@8.1.0

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

4 participants