ReactJS with Fetch on older browsers

I am using React JS with Webpack and Babel. However, I am having trouble getting Fetch to work with IE 11.

My .babelrc file has the following:

{
  "presets" : ["env", "stage-0", "react"]
}

      

and the following in webpack.config.js file:

var webpack = require('webpack');
var path = require('path');

var DIST_DIR = path.resolve(__dirname, 'dist');
var SRC_DIR = path.resolve(__dirname, 'src');

var config = {
  entry: {
    bundle: [
      'babel-polyfill',
      SRC_DIR + '/app/index.js',
    ]
  },
  output: {
    path: DIST_DIR + '/public/js',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        include: SRC_DIR,
        loader: 'babel-loader'
      }
    ]
  }
};

module.exports = config;

      

From my understanding, the implementation of babel-preset-env, stage-0 and babel-polyfill should have allowed the Fetch API to be refactored into something older browsers could understand. Is there something else that I am missing?

+3


source to share


2 answers


fetch

not part of EcmaScript, but part of the web platform ... Babylon is just a compilerto write the latest Javascript. If you want to use fetch

in older browsers you need a polyfill like this



Fetch API: Learn More

+2


source


fetch

must be available in the browser you are using and not included in babel-polyfill

. If your browser doesn't support fetch

you can either go back to using XMLHttpRequest

or use a polyfill like isomorphic-fetch .



0


source







All Articles