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

I'm using CommonJS! What should I do? #1789

Closed
szmarczak opened this issue Jul 16, 2021 · 5 comments
Closed

I'm using CommonJS! What should I do? #1789

szmarczak opened this issue Jul 16, 2021 · 5 comments

Comments

@szmarczak
Copy link
Collaborator

szmarczak commented Jul 16, 2021

Please read this.

If you can't move to ESM yet, please stay on the Got v11 branch.

Workarounds for Got v12

  1. Use await import('got').
  2. Use a wrapper: https://gist.github.com/szmarczak/0f2b70b2a1ed52a56a6d391ac02d094d
    Disclaimer: the first request needs to be a Promise.
  3. Use a third party module such as got-cjs: https://github.com/apify/got-cjs
@etnbrd
Copy link
Contributor

etnbrd commented Dec 16, 2021

Unfortunately, [email protected] depends on [email protected], which became an ESM only package as well, so I doubt these alternative would work anymore. I only briefly tested the second alternative got-cjs, though.
Additionally, got depends on node:events, which only make sense in ESM. But it should probably be easy to remove the node: part in the module specifier during the package publication.

The right direction to go is clearly to move to ESM.
But in the meantime, if there is enough support, maybe we could try to provide cjs versions of both got and p-cancelable, and it could buy enough time to migrate to ESM?

@szmarczak
Copy link
Collaborator Author

Node v12.22.0 has been released almost a year ago (2021-03-30) and it has brought stable support for ESM.
Moving back is very unlikely. Please use await import('got') or use got-cjs.

@etnbrd
Copy link
Contributor

etnbrd commented Dec 18, 2021

Ah, I didn't know it was possible to use await import('got') from CJS to import ESM package. I'll give that a try, thanks 🙇

Regarding got-cjs, latest version is v12.0.0-beta.4: https://www.npmjs.com/package/got-cjs?activeTab=versions
Which still uses [email protected] https://github.com/sindresorhus/got/blob/v12.0.0-beta.4/package.json#L57 which is not an ESM package: https://github.com/sindresorhus/p-cancelable/blob/v2.1.1/package.json

I tried to update got-cjs with latest [email protected] but it now depends on [email protected], which is an ESM package, and it imports node:events, which is incompatible with CJS. Because of these, the recompilation of [email protected] into [email protected] doesn't seem to be working with the current github-action. To keep got-cjs up-to-date, it seems we would have to recompile [email protected] as well, and update the dependencies to use p-cancelable-cjs and events instead of p-cancelable and node:events.

This might be time-consuming, so before trying that route, I just wanted to know if there is support, and if that's something we should consider.

@szmarczak
Copy link
Collaborator Author

@etnbrd got-cjs downgrades these deps and works flawlessly.

@sindresorhus
Copy link
Owner

Just closing this as it's pinned so it doesn't need to be open.

Repository owner deleted a comment from intech Feb 5, 2022
Repository owner locked as resolved and limited conversation to collaborators Feb 5, 2022
@sindresorhus sindresorhus unpinned this issue Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants