Giter Club home page Giter Club logo

Comments (9)

fokusferit avatar fokusferit commented on August 25, 2024 11

My current guess is that you need to tell babel-loader (if you use webpack) to target es5 ?
Currently, setting up a new project and having the same issue...

Edit: So I played around with webpack, included unfetch but then somehow babel-loader is not changing require(..) of the polyfill.mjs. Maybe it's something with .mjs?

Anyway here is how I got it running, when you check the polyfill folder, there is a index.js in the polyfill folder for now:

Changing:

import 'unfetch/polyfill'; to import 'unfetch/polyfill/index.js'; worked for me ^^.

from unfetch.

dwightjack avatar dwightjack commented on August 25, 2024 8

Encountered this issue as well.

I think the main problem is that many webpack configurations exclude node_modules from babel-loader thus shipping the arrow function.

Given that there is not yet consensus whether we should compile or not 3rd party library in node_modules It'd be nice to add a note on the docs requiring to include the polyfill in the compiled sources (or use 'unfetch/polyfill/index').

from unfetch.

developit avatar developit commented on August 25, 2024 3

Ah, it's pointing to the src version of unfetch:

https://github.com/developit/unfetch/blob/master/polyfill/polyfill.mjs#L1

That line should instead be:

import unfetch from '..';

from unfetch.

piotrblasiak avatar piotrblasiak commented on August 25, 2024 2

Having to transpile unfetch to make it work in what is said to be a supported browser is definitely not expected behaviour to me :) I would prefer if node_modules was expected to be transpiled - that way the bundles would be really optimized. But that is not the reality today.

Also, in order to transpile unfetch - don´t forget it uses .mjs files so you´ll need to do this in webpack/babel:

{
          test: /\.m?js$/,
          exclude: /node_modules\/(?!unfetch\/)/,
          use: "babel-loader"
        }

from unfetch.

japrogramer avatar japrogramer commented on August 25, 2024

still not working, Trying with ie11 and apollo-client as recommended by the packages.

from unfetch.

KrofDrakula avatar KrofDrakula commented on August 25, 2024

It works if you include unfetch/polyfill/index and your transpiler targets IE11. Unless you explicitly exclude node_modules, it should compile just fine.

I don't really know why it wouldn't compile the polyfill by default, though. I've set webpack to not exclude node_modules.

from unfetch.

developit avatar developit commented on August 25, 2024

regarding @ikevanc's other issue - the unpkg hotlinking worked, unfetch doesn't polyfill Headers. This may change in the future, but the current recommendation is to just use an object.

from unfetch.

mo avatar mo commented on August 25, 2024

@developit I ran into this bug as well today and switching to "unfetch/polyfill/index" worked well as a workaround. Does your jan 15th comment about '..' mean that this is a bug that you intend to fix eventually?

from unfetch.

bdrobinson avatar bdrobinson commented on August 25, 2024

Yeah this tripped me up too – probably quite an important fix as this would be a pretty difficult bug for newcomers to identify and work around?

from unfetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.