[英]Can I ignore Unexpected reserved word error by eslint-loader
我正在使用最新的React,Babel,因此也是他们必要的预设。
我的应用程序正常运行,不会吐出任何控制台错误。
但是,我从eslint-loader
收到以下错误。
我怎么能解决这个问题?
我的控制台
blog git:(master) ✗ webpack -w -d
Hash: 96cef29fd40f9ab86ee5
Version: webpack 1.12.9
Time: 1305ms
Asset Size Chunks Chunk Names
bundle.js 3.75 kB 0 [emitted] main
bundle.js.map 2.07 kB 0 [emitted] main
+ 1 hidden modules
ERROR in ./app/assets/frontend/app.jsx
/Users/seoyoochan/dev/blog/app/assets/frontend/app.jsx
1:2 error Parsing error: Unexpected reserved word
✖ 1 problem (1 error, 0 warnings)
webpack.config.js
module.exports = {
entry: "./app/assets/frontend/app.jsx",
output: {
path: __dirname + "/app/assets/javascripts",
filename: "bundle.js"
},
resolve: {
extensions: ["", ".js", ".jsx"]
},
module: {
preLoaders: [
{
test: /.jsx?$/,
loader: "eslint-loader",
exclude: /bundle\.js$/
}
],
loaders: [
{
test: /.jsx?$/,
loader: "babel",
exclude: /node_modules/,
query: {
cacheDirectory: true,
presets: ["es2015", "react"]
}
}
]
}
};
app.jsx
class App extends React.Component {
render() {
return (<h1>hello !</h1>);
}
}
let documentReady = () => {
ReactDOM.render(<App/>, document.getElementById('app'));
};
$(documentReady);
您可能需要配置eslint以了解jsx。 使用以下内容创建.eslintrc
文件:
{
"ecmaFeatures": {
"jsx": true
}
}
有关可能在将来为您抛出错误的完整配置列表, 请参阅文档
我配置了eslint来理解jsx,所以这里是这个错误的逐步解决方案。
使用以下内容创建.elintrc文件
{“ecmaFeatures”:{“jsx”:true}}
在webpack.config.js中添加以下内容
module.exports = {... module:{preLoaders:[{test:/.js?$ /,loader:“eslint-loader”,exclude:/bundle.js$/}],loaders:[{test:/ .jsx?$ /,loader:“babel”,exclude:/ node_modules /,query:{cacheDirectory:true,presets:[“es2015”,“react”]}}]},eslint:{configFile:'。/。 eslintrc'}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.