无法使用Babel导出reducer

时间:2016-02-25 10:10:51

标签: javascript ecmascript-6 babeljs es6-module-loader

这很可能是一些错字,但我一直试图在最后一小时修复它并且没有任何结果。

我有一个名为app/reducers/index.js的文件:

export viewportSize from "./viewportSize";

app/reducers/viewportSize.js只是:

export default function viewportSize (state = {}) {
  return state;
}

app/app.js我做:

import reducers from "./reducers";

Babel正在回复此错误

ERROR in ./app/reducers/index.js
1:8  error  Parsing error: Unexpected token viewportSize

我在项目中有其他importexport,但是这个并不想工作。

这是我的.babelrc文件:

{
  "presets": ["es2015", "react", "stage-2"]
}

更新

这些是我的依赖

  "devDependencies": {
    "babel-core": "6.5.2",
    "babel-loader": "6.2.3",
    "babel-preset-es2015": "6.5.0",
    "babel-preset-react": "6.5.0",
    "babel-preset-stage-2": "6.5.0",
    "eslint": "2.2.0",
    "eslint-loader": "1.3.0",
    "eslint-plugin-react": "4.1.0",
    "file-loader": "0.8.5",
    "react-hot-loader": "1.3.0",
    "webpack": "1.12.14",
    "webpack-dev-server": "1.14.1"
  },
  "dependencies": {
    "babel-preset-stage-0": "6.5.0",
    "immutable": "3.7.6",
    "react": "0.14.7",
    "react-dom": "0.14.7",
    "react-redux": "4.4.0",
    "react-router": "2.0.0",
    "react-router-redux": "4.0.0",
    "redux": "3.3.1"
  }

更新

这是我的webpack配置文件

var webpack = require("webpack");

module.exports = {
  context: __dirname + "/app",
  entry: {
    javascript: "./app.js",
    html: "./index.html",
    css: "./style.css",
  },

  output: {
    filename: "app.js",
    path: __dirname + "/dist",
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
  ],

  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        include: __dirname,
        loaders: ["react-hot", "babel-loader", "eslint-loader"],
      },
      {
        test: /\.html$/,
        loader: "file?name=[name].[ext]",
      },
      {
        test: /\.css$/,
        loader: "file?name=[name].[ext]",
      },
    ],
  },
};

0 个答案:

没有答案