I'm writing a react app with babel and webpack. It's been going along well until I tried to add a property on a class - specifically trying to use a Dropdown from React-Toolbox (http://react-toolbox.com/#/components/dropdown) and for the time being before getting data connected, I directly copied this:
class DropdownTest extends React.Component {
state = {
value: 'ES-es',
};
handleChange = (value) => {
this.setState({value: value});
};
render () {}
Here is my very-slightly-modified version:
class ChordFilters extends Component {
state = {
value: 'Mandolin',
};
handleChange = (value) => {
this.setState({value: value});
};
render() {
As soon as I added the state
object, I got an error in webpack: Syntax Error, unexpected Token
, at the 'state =' declaration. Here's the full error:
at Parser.pp.raise (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.unexpected (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/util.js:82:8)
at Parser.pp.parseClassProperty (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/statement.js:624:61)
at Parser.parseClassProperty (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/plugins/flow.js:797:20)
at Parser.pp.parseClass (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/statement.js:567:32)
at Parser.pp.parseStatement (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/statement.js:84:19)
at Parser.parseStatement (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/plugins/flow.js:621:22)
at Parser.pp.parseTopLevel (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/statement.js:30:21)
at Parser.parse (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/parser/index.js:70:17)
at Object.parse (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babylon/lib/index.js:45:50)
at Object.exports.default (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/helpers/parse.js:36:18)
at File.parse (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/transformation/file/index.js:574:40)
at File.parseCode (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/transformation/file/index.js:691:20)
at /Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/transformation/pipeline.js:167:12
at File.wrap (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/transformation/file/index.js:639:16)
at Pipeline.transform (/Users/amaiale/chordb/node_modules/babel-loader/node_modules/babel-core/lib/transformation/pipeline.js:165:17)
I haven't run into this before but previously I only had methods declared on the class.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…