Anthony Kong
Anthony Kong

Reputation: 40674

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?

Upvotes: 9

Views: 1698

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40674

whatwg-fetch is actually a polyfill

I only need to import it this way:

import 'whatwg-fetch';

Upvotes: 12

Related Questions