lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.67k stars 104 forks source link

added native ESM version for node. #61

Closed d-fischer closed 4 years ago

d-fischer commented 4 years ago

Currently, using this package with native ESM loading fails with an error like this:

import { fetch, Headers } from 'cross-fetch';
         ^^^^^
SyntaxError: The requested module 'cross-fetch' does not provide an export named 'fetch'

This pull request fixes that by adding a separate ESM version of the ponyfill and referencing it in the exports key of package.json. The polyfill doesn't need a special version (since it doesn't export anything) but still needs to be referenced in the exports.

lquixada commented 4 years ago

Hey @d-fischer! Thanks for your PR! It's really interesting to see how a ESM package would look like.

However, since ESM in Node is still in the experimental stage I feel it wouldn't be a good idea to make it available to the general public as the API may change in the future. If some app begins relying on it, it might break on future cross-fetch versions (possibly many times).

d-fischer commented 3 years ago

Can this get another review since nodejs/node@73ea6701524974ce388e87b5f3cc2f9aa181933f will land in node 15.3.0?