Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack/babel/es6 import issue - (0 , _whatwgFetch2.default) is not a function

I am importing whatwg-fetch(https://github.com/github/fetch) into my app

import fetch from 'whatwg-fetch';

For local development I use webpack-dev-server. I got this error message:

 test.js?ba55:67 Uncaught TypeError: (0 , _whatwgFetch.fetch) is not a function

It is fired from this line:

fetch('/api/mydata', opts)

Why the import failed?

like image 662
Anthony Kong Avatar asked Mar 24 '16 05:03

Anthony Kong


1 Answers

whatwg-fetch is actually a polyfill

I only need to import it this way:

import 'whatwg-fetch';
like image 169
Anthony Kong Avatar answered Oct 16 '22 05:10

Anthony Kong