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

Move to ESM #999

Closed
mesqueeb opened this issue Feb 23, 2021 · 18 comments
Closed

Move to ESM #999

mesqueeb opened this issue Feb 23, 2021 · 18 comments

Comments

@mesqueeb
Copy link

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

@LitoMore
Copy link
Sponsor Collaborator

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 LitoMore changed the title upgrade to esm Move to ESM Apr 24, 2021
@LitoMore LitoMore pinned this issue May 24, 2021
@axelrindle
Copy link

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.

@mesqueeb
Copy link
Author

@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.

@jimmywarting
Copy link
Contributor

jimmywarting commented Oct 27, 2021

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

@SBoudrias
Copy link
Owner

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

@un-focused
Copy link
Contributor

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

@softmarshmallow
Copy link

softmarshmallow commented Jul 31, 2022

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

@SBoudrias
Copy link
Owner

SBoudrias commented Aug 1, 2022

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.

@billyjacoby
Copy link

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

@MrSharpp
Copy link

MrSharpp commented Aug 13, 2022

i fixed it by downgrading to version 8.0.1

@harvzor
Copy link

harvzor commented Aug 16, 2022

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.

@SBoudrias
Copy link
Owner

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

But I've opened this one here #1159 to offer a common.js build output too. Help welcome on this task.

@cheng-alvin
Copy link

i fixed it by downgrading to version 8.0.1

This worked as well thanks!!

@Lukrisum
Copy link

i fixed it by downgrading to version 8.0.1

This works, thanks a lot !!

@cheng-alvin
Copy link

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??

@SBoudrias
Copy link
Owner

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.

@cheng-alvin
Copy link

Ok thanks

@LitoMore LitoMore unpinned this issue Mar 17, 2023
@ORESoftware
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests