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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in browser? (needs es module version?) #149

Open
daKmoR opened this issue Dec 21, 2022 · 0 comments
Open

Does not work in browser? (needs es module version?) #149

daKmoR opened this issue Dec 21, 2022 · 0 comments
Labels

Comments

@daKmoR
Copy link

daKmoR commented Dec 21, 2022

hey,

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>
  1. server it with any webserver (npx http-server, apache, nginx...)
  2. 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

  "exports": {
    ".": {
      "require": "./dist/node-ponyfill.js",
      "browser": "./dist/browser-ponyfill.js",
      "default": "./dist/es-module-ponyfill.js"
    }
  },

What do you think?

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

No branches or pull requests

2 participants