我正在尝试使用" context"在我的es6反应代码,但捆绑我得到这个错误
export default class Layout extends React.Component {
static contextTypes = {
LayoutURL : React.PropTypes.string
};
constructor(props, context) {
super(props, context);
this.state = {
}
}
}
"模块构建失败:TypeError:_jsTokens2.default.matchToToken不是函数"
PFB我的webpack代码(我已经添加了es6,但错误仍然存在)我的webpack版本是" ^ 1.13.0"
module.exports = {
entry: './main.js',
output: { path: __dirname, filename: 'bundle.js' },
devServer: {
inline: true,
port: 8085
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
}
]
},
resolve: {
extensions: ['', '.js', '.jsx','.es6']
},
};
答案 0 :(得分:0)
我发现err是由于语法引起的。更新的语法:
export default class Layout extends React.Component {
constructor(props, context) {
super(props, context);
this.state = { //state initialization }
}
}
Layout.contextTypes={
LayoutURL : React.PropTypes.string
};