错误:无法解析'babel-loader'

时间:2017-08-21 22:28:44

标签: webpack babel-loader

我收到此错误,请你帮我。以下是我的webpack.config和package.JSON文件。我的服务器工作正常,但没有webpack.I全局安装了Webpack但是没有解决这个问题。

=== webpack.config file ===

var path = require('path');
const webpack = require('webpack');
module.exports = {
  entry: './src/app.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'public')
  },
watch: true,
module: {
  loaders: [
    {
      test:/\.js$/,
      exclude:/node_modules/,
      loader: 'babel-loader',
      query: {
        presets: ['react', 'es2015', 'stage-1']
      }
    }

  ]
}

=== Package.JSON文件===

{
  "name": "reduxApp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^3.5.5"
  },
  "dependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-1": "^6.24.1",
    "express": "^4.15.4",
    "loader": "^2.1.1",
    "redux": "^3.7.2"
  }
}

1 个答案:

答案 0 :(得分:3)

此软件包允许使用Babel和webpack转换JavaScript文件。

此任务所需的只是添加实际加载程序和env预设为开发依赖项npm install -D babel-loader babel-preset-env

在您的webpack配置对象中,您需要将babel-loader添加到模块列表中,如下所示:

module: { rules: [ { test: /\.js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: ['env'] } } } ] }