来自react的提供者 - redux意外令牌

时间:2016-08-23 14:15:46

标签: javascript node.js webpack react-redux

使用' react-redux'我收到这个错误:

    ERROR in ./client/index.js
Module parse failed: /Users/flystyle/WebstormProjects/peredovaya-game-beg/client/index.js Unexpected token (14:2)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (14:2)
    at Parser.pp$4.raise (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp$3.parseExprAtom (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1822:12)
    at Parser.pp$3.parseExprSubscripts (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1715:21

)
    at Parser.pp$3.parseMaybeUnary (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1620:
21)
    at Parser.pp$3.parseMaybeAssign (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1597:21)
    at Parser.pp$3.parseExprList (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:2165:22)
    at Parser.pp$3.parseSubscripts (/Users/flystyle/WebstormProjects/peredovaya-game-beg/node_modules/acorn/dist/acorn.js:1741:35)
 @ multi main

当我按npm run server启动时。 我该如何解决?我是JS的新手。

/client/index.js的内容:

import React from 'react';
import { render } from 'react-dom';
import { Router, browserHistory } from 'react-router';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { createStore, applyMiddleware } from 'redux';

import routes from './routes';

const store = createStore(
  (state = {}) => state, applyMiddleware(thunk));

render(
  <Provider store={store}>       /// <--- this row.
    <Router history={browserHistory} routes={routes} />
  </Provider>, document.getElementById('game'));

/client/routes.js的内容:

import React from 'react';
import { Route, IndexRoute } from 'react-router';

import Game from './components/game';
import Greetings from './components/Greetings';
import SignupPage from './components/signup/SignUpPage';


export default (
  <Route path="/" component={Game}>
    <IndexRoute component={Greetings} />
    <Route path="signup" component={SignupPage} />
  </Route>
)

package.json的内容:

{
  "name": "peredovaya-game-beg",
  "version": "0.0.1-dev",
  "description": "Peredovaya game clone",
  "main": "app.js",
  "scripts": {
    "server": "nodemon --watch server --exec babel-node -- ./server/app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "peredovaya"
  ],
  "author": "Fly-Style",
  "license": "MIT",
  "devDependencies": {
    "babel-cli": "^6.11.4",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-react": "^6.11.1",
    "css-loader": "^0.23.1",
    "react-hot-loader": "^1.3.0",
    "underscore": "^1.8.3",
    "webpack": "^1.13.1",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-hot-middleware": "^2.12.2"
  },
  "dependencies": {
    "axios": "^0.13.1",
    "bcrypt": "^0.8.7",
    "bluebird": "^3.4.1",
    "body-parser": "^1.15.2",
    "bootstrap": "^3.3.7",
    "classnames": "^2.2.5",
    "express": "^4.14.0",
    "jquery": "^3.1.0",
    "jsonwebtoken": "^7.1.7",
    "jwt-decode": "^2.1.0",
    "knex": "^0.11.7",
    "lodash": "^4.13.1",
    "mongodb": "^2.2.5",
    "pg": "^6.0.2",
    "react": "^15.3.0",
    "react-dom": "^15.3.0",
    "react-redux": "^4.4.5",
    "react-router": "^2.5.0",
    "redux": "^3.5.2",
    "redux-thunk": "^2.1.0",
    "request": "^2.74.0",
    "shortid": "^2.2.6",
    "socket.io": "^1.4.8",
    "validator": "^5.4.0"
  }
}

/webpack.config.dev.js的内容:

import path from 'path';
import webpack from 'webpack';

export default {
  devtools: 'eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    path.join(__dirname, '/client/index.js')
  ],
  output: {
    path: '/',
    publicPath: '/'
  },
  plugins: [
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        test: /\.css$/, loader: "style-loader!css-loader",
        include: [
          path.join(__dirname, 'client'),
          path.join(__dirname, 'server/shared')
        ],
        loaders: [ 'react-hot', 'babel' ]
      }
    ]
  },
  resolve: {
    extentions: [ '', '.js' ]
  }
}

'.babelrc'的内容:

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

0 个答案:

没有答案