ES6 `fetch is undefined`

后端 未结 8 894
太阳男子
太阳男子 2020-12-02 16:27

I\'m building a site with ES6 and Babel.

In a script file, I need to make an ajax call to a service on server. For that I\'m doing like this:

fetch(\         


        
相关标签:
8条回答
  • 2020-12-02 17:27

    You need to add the 'isomorphic-fetch' module to your 'package.json' and then import this.

    npm install --save isomorphic-fetch es6-promise
    

    Then in your code

    import "isomorphic-fetch"
    

    See https://www.npmjs.com/package/isomorphic-fetch

    0 讨论(0)
  • 2020-12-02 17:27

    Babel-polyfill (http://babeljs.io/#polyfill) currently doesn't include fetch in the polyfill. I was thinking of adding it though.

    But yeah can use https://github.com/github/fetch

    0 讨论(0)
提交回复
热议问题