Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Move to ESM

Open mesqueeb opened this issue 4 years ago • 8 comments

some reading on this: https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77

mesqueeb avatar Feb 23 '21 22:02 mesqueeb

Hi @mesqueeb! Thank you for notifying us!

Here are my concerns about pure ES Module packages:

  • We must use import to load ES Module, which means the user's package must be ES Module too.
  • In ESM, we cannot use __dirname related things anymore, which means some users have to refactor their code for applying our new version.

At last, I agree with pushing our ecosystem forward. We could keep this issue open for a while and let other developers know we plan to do this.

Cheers to ESM!

LitoMore avatar Apr 24 '21 11:04 LitoMore

I don't like the idea of packages forcing it's users to use a specific module system. The community should rather strive to make both systems fully interoperable.

axelrindle avatar Jul 29 '21 19:07 axelrindle

@axelrindle NodeJS already works with import natively. If you want to use legacy NodeJS versions you can simply use an older version of the package you wanna use.

mesqueeb avatar Jul 30 '21 00:07 mesqueeb

I agree that we should strive towards esm also ppl stuck with cjs can still import esm only packages using dynamic import('x') the only nit pick is that it needs to be async, everyone don't have to move to esm just b/c we decide to do so

You depend on quite some few packages from @sindresorhus that all been switched to esm-only. so to get new updates it would be great to also switch to esm

jimmywarting avatar Oct 27 '21 16:10 jimmywarting

PR welcomed to implement ESM modules. It's been out a while, I think it's time to rip the bandaid.

SBoudrias avatar Mar 09 '22 00:03 SBoudrias

Hi @SBoudrias , I made a Pull Request for this feature. Please check it out when you have time :)

un-focused avatar May 06 '22 18:05 un-focused

Pinging for ts users. Came here with below error.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
.../node_modules/inquirer/lib/inquirer.js
require() of ES modules is not supported.

Seems no other way than givving up using ts-node. switching back to classic enquirer

softmarshmallow avatar Jul 31 '22 18:07 softmarshmallow

I answered this over this other thread - please refrain from sharing misinformation out of frustration... This isn't helpful for anyone.

If you want to use ts-node with esm, you need to add this configuration to your ts-config.json https://github.com/SBoudrias/Inquirer.js/blob/master/tsconfig.json#L4-L6 - I've been developing inquirer using ts-node.

SBoudrias avatar Aug 01 '22 12:08 SBoudrias

I have this line added to my ts-config but i continue to get the same Error [ERR_REQUIRE_ESM]: require() of ES Module error

billyjacoby avatar Aug 13 '22 15:08 billyjacoby

i fixed it by downgrading to version 8.0.1

MrSharpp avatar Aug 13 '22 17:08 MrSharpp

I don't understand what's going on here but downgrading to 8.0.1 helped me too.

I'm trying to use ESM modules with TypeScript and Jest. Version 9.1.0 of Inquirer causes Jest to throw:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From src/fileSystem.test.ts.

          at async Promise.all (index 1)

Commenting out any code which uses Inquirer and running the test works.

harvzor avatar Aug 16 '22 15:08 harvzor

Since the ESM migration was done, I'll close this ticket.

But I've opened this one here https://github.com/SBoudrias/Inquirer.js/issues/1159 to offer a common.js build output too. Help welcome on this task.

SBoudrias avatar Aug 19 '22 13:08 SBoudrias

i fixed it by downgrading to version 8.0.1

This worked as well thanks!!

cheng-alvin avatar Nov 11 '22 21:11 cheng-alvin

i fixed it by downgrading to version 8.0.1

This works, thanks a lot !!

Lukrisum avatar Nov 30 '22 20:11 Lukrisum

i fixed it by downgrading to version 8.0.1

I mean, could this make us sacrifice in security or features? Can you guys add an option to use BOTH module systems??

cheng-alvin avatar Dec 01 '22 05:12 cheng-alvin

Can you guys add an option to use BOTH module systems?

Like I posted, this is tracked in #1159. I'd be happy to review a PR and facilitate a release about this if you're ready to help.

SBoudrias avatar Dec 01 '22 14:12 SBoudrias

Ok thanks

cheng-alvin avatar Dec 14 '22 08:12 cheng-alvin

libraries should be able to support both without needing downgrade versions - if it can't then that's node.js is fault

ORESoftware avatar Mar 19 '24 20:03 ORESoftware