2017-04-20 61 views
0

React tutorial series的中途,在mapStateToProps结尾处出现错误。就我所知,我的代码与本教程中的代码相同。npm run build中的SyntaxError/React

在命令行:

> npm run build 
> SyntaxError: /home/jake/web/flashcards/src/components/App.js: Unexpected token (5:22) while parsing file: /home/jake/web/flashcards/src/components/App.js 

这是App.js:

import React from 'react'; 
import Sidebar from './Sidebar'; 
import {connect} from 'react-redux'; 

const mapStateToProps (props, {params:{deckId}}) => ({ 
    deckId 
}); 

const App = ({deckId, children}) => { 
    return(<div className ='app'> 
     <Sidebar /> 
     <h1> Deck {deckId} </h1> 
      {children} 
     </div>); 
}; 

export default connect(mapStateToProps)(App); 

我的package.json:

{ 
    "name": "flashcards", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "build": "watchify src/app.js -o public/bundle.js -t [ babelify --presets [ react es2015 ] ]", 
    "server": "cd public; live-server --port=1236 --entry-file=index.html" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "babel-preset-es2015": "^6.24.1", 
    "babel-preset-react": "^6.24.1", 
    "babelify": "^7.3.0", 
    "live-server": "^1.2.0", 
    "react": "^15.5.4", 
    "react-dom": "^15.5.4", 
    "react-redux": "^5.0.4", 
    "react-router": "^3.0.2", 
    "react-router-redux": "^4.0.8", 
    "redux": "^3.6.0", 
    "watchify": "^3.9.0" 
    } 
} 

回答

1

初始化的常量声明

const mapStateToProps = 
         ^^ 
2

缺少等号:

const mapStateToProps = (props, {params:{deckId}}) => ({ 
    deckId 
}); 
相关问题