Cannot find module babel-preset-es2015

前端 未结 2 1536
隐瞒了意图╮
隐瞒了意图╮ 2020-12-25 10:34

Getting same error again again: Error: Cannot find module \'babel-preset-es2015\'.

Full error log:

ERROR in ./main.js M         


        
相关标签:
2条回答
  • 2020-12-25 10:50

    Thing in that the babel 7 uses @babel/preset-env. Other presets are deprecated Here saying about this https://babeljs.io/docs/en/v7-migration#yearly-preset-deprecations-blog-2017-12-27-nearing-the-70-releasehtml-deprecated-yearly-presets-eg-babel-preset-es20xx

    You should specify in a configuration file (I don't know if you are using Webpack or something else) preset as "@babel/preset-env". Install it through npm install --save-dev @babel/preset-env

    For example, you are using Webpack module bundler. In that case, specify like this:

    use: {
          loader: "babel-loader",
          options: {
                    presets: ["@babel/preset-env"]
          }
    }
    

    Here is a documentation https://webpack.js.org/loaders/babel-loader/ if you suddenly will need.

    Happy coding!

    0 讨论(0)
  • 2020-12-25 11:14

    For Babel version 6 the package name is babel-preset-es2015 and for Babel version 7 the package name is @babel/preset-es2015.

    From the error it seems that you're using version 7. The es20XX-presets are deprecated, so I recommend you switch to @babel/preset-env.

    First install the preset (using npm):

    npm install --save-dev @babel/preset-env
    

    Then add the preset to your .babelrc

    {
        presets: ["@babel/preset-env"]
    }
    
    0 讨论(0)
提交回复
热议问题