Fetch polyfill in React not completely working in IE 11

前端 未结 4 481
刺人心
刺人心 2021-01-07 02:53

This fetch works fine in Chrome:

fetch( this.props.url, {credentials:\'same-origin\'})
    .then( (data) => data.js         


        
4条回答
  •  攒了一身酷
    2021-01-07 03:42

    Looking at isomorphic-fetch, the package is just a meta-package of sorts that import-exports either whatwg-fetch or node-fetch depending on whether you are in a browser or Node context.

    I think your issue is that it will use the node version by default (see the main entry in the package.json).

    Being a polyfill, it is simply skipped on non-IE as the browsers support fetch by default. On IE11 the polyfill is used, but it's the Node polyfill which won't work in a browser.

    You might be able to coerce webpack to use the browser version by including the browser specific version:

    require('isomorphic-fetch/fetch-npm-browserify')
    

    or

    import 'isomorphic-fetch/fetch-npm-browserify'
    

    or in Webpack config:

    entry: [
        'isomorphic-fetch/fetch-npm-browserify',
        'app.js'
    ]
    

提交回复
热议问题