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

oclif incompatible with inquirer 9 - prompting guide broken #476

Closed
Peter-Piper opened this issue Aug 19, 2022 · 6 comments · Fixed by oclif/oclif.github.io#203
Closed
Labels
bug Something isn't working

Comments

@Peter-Piper
Copy link

Describe the bug
Disclaimer: I'm unsure which of the projects actually contains this bug, but here goes.

I'm trying out oclif version oclif/3.1.2 darwin-x64 node-v18.7.0 following the documentation on prompts.

I've copied line by line from the example in the docs installing inquirer and types defs for version 9.1.0.
This results in a whole sequence of issues:

  1. First issue I encounter is that ".prompt" doesn't exist on inquirer
    This is solved by replacing the import statement from import * as inquirer from 'inquirer' to import inquirer from 'inquirer'

However, changing the import statement followed by a yarn prepack results in the following error

$ yarn prepack
yarn run v1.22.17
$ yarn build && oclif manifest && oclif readme
$ shx rm -rf dist && tsc -b
    Error Plugin: admin-cli: require() of ES Module /Users/peterp/NSS/grid/scripts/admin/admin-cli/node_modules/inquirer/lib/inquirer.js from /Users/peterp/NSS/grid/scripts/admin/admin-cli/dist/commands/cellinfo/upload.js not
     supported.
    Instead change the require of inquirer.js in /Users/peterp/NSS/grid/scripts/admin/admin-cli/dist/commands/cellinfo/upload.js to a dynamic import() which is available in all CommonJS modules.
    Code: ERR_REQUIRE_ESM
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Inquirer is a pure ESM project since version 9.

I tried following the typescript guide on how to convert from commonjs til module, however this introduces a whole range of other issues with the entire project

My current solution is to roll back to inquirer@8 and @types/inquirer@8. But that prevents any future patches from inquirer and all of the cool inquirer plugins :-(

To Reproduce
Steps to reproduce the behavior:

  1. Follow the official oclif prompting guide https://oclif.io/docs/prompting

Expected behavior
It should work with inquirer.js 9+

Environment (please complete the following information):

  • OS & version: macOS Big Sur 11.6.8
  • Shell/terminal & version: zsh 5.8 (x86_64-apple-darwin20.0)
  • oclif version: oclif/3.1.2 darwin-x64 node-v18.7.0
  • node version: v18.7.0
  • inquirer v9.1.0
@Peter-Piper Peter-Piper added the bug Something isn't working label Aug 19, 2022
@jbournonville
Copy link

Any news on that issue ?

@himerus
Copy link

himerus commented Oct 15, 2022

Seeing the same thing as I attempt to use the latest version of inquirer with oclif. Revering inquirer back to 8.x works as it has in other of my projects/tests.

@motabass
Copy link

motabass commented Oct 24, 2022

The reason is, pretty sure, that inquirer moved to ESM: https://github.com/SBoudrias/Inquirer.js/releases/tag/inquirer%409.0.0

I also struggle to move our cli to ESM to make the latest inquirer work, and also zx which also uses ESM since v5: https://github.com/google/zx/releases/tag/5.0.0

Any help or guide on how to migrate a CLI project to ES Modules would be highly appreciated, especially when aslo using typescript.

#256 seems also to talk about that topic

@deprosun
Copy link

deprosun commented May 1, 2023

I was facing the below issue

Cannot find module './lib/screen-manager.mjs'

and had to resolve also by rolling back to inquirer@8 and @types/inquirer@8

@AutomationD
Copy link

AutomationD commented Jul 26, 2023

1 year, guide is still broken.

Adding package version to the guide would mitigate this issue.

@cristiand391
Copy link
Member

Hey all, sorry we missed this issue.

As pointed above, inquirer fully moved to ESM in v9. The current example works in an ESM plugin but we added a new one for CJS CLIs that still want to use latest inquirer:
https://oclif.io/docs/prompting#inquirer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants