I wanted to give this a quick try and assumed that this works
👉 index.html
<script type="module">
import { fetch } from './node_modules/cross-fetch/dist/browser-ponyfill.js';
console.log(fetch);
</script>
server it with any webserver (npx http-server, apache, nginx...)
open it in the browser
Expected output
Logs fetch implementation
Actual output
Uncaught SyntaxError: The requested module './node_modules/cross-fetch/dist/browser-ponyfill.js' does not provide an export named 'fetch' (at index.html:2:12)
Ideas
No surprise there as the browser-ponyfill is NOT an actual es module.
e.g. it would need an export default fetch and not an module.exports = fetch in it's code.
Is it worth it to create an additional entrypoint for es modules?
something like dist/es-module-ponyfill.js?
would probably be good to add it via package entrypoints... e.g. something like this in the package.json
hey,
I wanted to give this a quick try and assumed that this works
👉
index.html
Expected output
Logs fetch implementation
Actual output
Ideas
No surprise there as the browser-ponyfill is NOT an actual es module. e.g. it would need an
export default fetch
and not anmodule.exports = fetch
in it's code.Is it worth it to create an additional entrypoint for es modules? something like
dist/es-module-ponyfill.js
?would probably be good to add it via package entrypoints... e.g. something like this in the
package.json
What do you think?