本文介绍了错误:找不到预设“es2015";相对于目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当我尝试使用 babel 时出现以下错误.

I get the following error when I trying to use babel.

错误:找不到相对于目录的预设es2015"

webpack.config.js

module.exports = {
    entry: './main.js',
    ourput: {
        path:'./',
        filename:'index.js'
    },
    devServer:{
        inline:true,
        port:3333
    },
    module:{
        loaders:[
            {
                test:/.js$/,
                exclude:/node_modules/,
                loader:'babel',
                query:{
                    presets:['es2015','react']
                }
            }
        ]
    }
}

package.json

package.json

{
  "name": "es6-react-setup",
  "version": "1.0.0",
  "main": "main.js",
  "dependencies": {
    "babel-core": "^6.11.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1",
    "babel-loader": "^6.2.4",
    "react": "^15.2.1",
    "react-dom": "^15.2.1",
    "webpack": "^1.13.1"
  },
  "devDependencies": {},
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

终端输出

推荐答案

您需要配置 babel 以使用这些预设.您可以将此添加到您的 package.json

You need to have babel configured to use those presets. You can add this to your package.json

  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  },

你也可以有一个 .babelrc 文件.

You can alternatively have a .babelrc file.

https://babeljs.io/docs/usage/babelrc/

这篇关于错误:找不到预设“es2015";相对于目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:09