core
core copied to clipboard
oclif incompatible with inquirer 9 - prompting guide broken
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:
- 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'
toimport 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:
- 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
Any news on that issue ?
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.
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.
https://github.com/oclif/core/issues/256 seems also to talk about that topic
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
1 year, guide is still broken.
Adding package version to the guide would mitigate this issue.
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