anc95 / inquirer-file-tree-selection

inquirer prompt for select a file or dir by file tree
49 stars 25 forks source link

Require of ES module #53

Closed kamack38 closed 2 years ago

kamack38 commented 2 years ago

You are using an ESM package (chalk) with require(). If you want to keep using require instead of ESM you'll have to use Chalk 4.

Read more Chalk 5 changelog

Log output:

C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\inquirer-file-tree-selection-prompt\dist\index.js:15
const chalk = require('chalk');
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\chalk\source\index.js from C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\inquirer-file-tree-selection-prompt\dist\index.js not supported.
Instead change the require of C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\chalk\source\index.js in C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\inquirer-file-tree-selection-prompt\dist\index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\ProgramData\nvm\v16.14.0\node_modules\solve3-cli\node_modules\inquirer-file-tree-selection-prompt\dist\index.js:15:15)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}
kamack38 commented 2 years ago

You can also use dynamic import() which is supported in both CommonJS and ES modules.

anc95 commented 2 years ago

@kamack38 Thanks for your report. you can downgrade version to 1.0.15 temporarily. I will work on fixing this right now

anc95 commented 2 years ago

@kamack38 It should be fixed on 1.0.17. I downgrade the dep's version. Initially, I plan to support node ESM in this lib (inquirer-file-tree-selection). But it seems InquirerJS itself does not support ESM, so leave it to one day when InquireJS supports ESM.

rclarkem-fubotv commented 2 years ago

Will this change since inquirer now uses ESM in the newest version?

Inquirer v9 and higher are native esm modules, this mean you cannot use the commonjs syntax require('inquirer') anymore.

anc95 commented 2 years ago

@rclarkem-fubotv Good to hear that inquirer supports ESM now, I will adapt ESM module too. Reopen this issue for tacking purpose

anc95 commented 2 years ago

Hello @rclarkem-fubotv, I just released version 2.0.0, enhanced the ESM support. You can reach out here for examples. Hope you enjoy with it, and look forward to your feedback.

I will close this issue, if you encounter any problem, feel free to open a new issue to let me fix it. 😄

rclarkem-fubotv commented 2 years ago

Hello @rclarkem-fubotv, I just released version 2.0.0, enhanced the ESM support. You can reach out here for examples. Hope you enjoy with it, and look forward to your feedback.

I will close this issue, if you encounter any problem, feel free to open a new issue to let me fix it. 😄

Dude (or Dudette), You are awesome! 🔥👍

Thanks!