How do I install the babel-polyfill library?

后端 未结 7 1335
旧时难觅i
旧时难觅i 2020-12-02 06:13

I just started to use Babel to compile my ES6 javascript code into ES5. When I start to use Promises it looks like it\'s not working. The Babel website states support for pr

7条回答
  •  春和景丽
    2020-12-02 06:58

    If your package.json looks something like the following:

      ...
      "devDependencies": {
        "babel": "^6.5.2",
        "babel-eslint": "^6.0.4",
        "babel-polyfill": "^6.8.0",
        "babel-preset-es2015": "^6.6.0",
        "babelify": "^7.3.0",
      ...
    

    And you get the Cannot find module 'babel/polyfill' error message, then you probably just need to change your import statement FROM:

    import "babel/polyfill";
    

    TO:

    import "babel-polyfill";
    

    And make sure it comes before any other import statement (not necessarily at the entry point of your application).

    Reference: https://babeljs.io/docs/usage/polyfill/

提交回复
热议问题