Can I ignore an unexpected eslint-loader reserved word error

I use the latest React, Babel and therefore their required presets.
My applications work correctly and do not spit on a console error.
However, I get the following error from eslint-loader.
how can i solve this problem?

my console

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);
+4
source share
2 answers

I configured eslint to understand jsx, so here is a step-by-step solution for this error.

  • create a .elintrc file with the following

    {"ecmaFeatures": {"jsx": true}}

  • add the following to webpack.config.js

    module.exports = { ... : {    preLoaders: [      {        test:/.js?$/,        : "eslint-loader",        :/bundle.js$/      }    ],    : [      {        test:/.jsx?$/,        : "babel",        :/node_modules/,        query: {          cacheDirectory: true,          : [ "es2015", "" ]        }      }    ]  }, eslint: {    configFile: './.eslintrc' } }

-1

, , eslint jsx. .eslintrc :

{
  "ecmaFeatures": {
      "jsx": true
  }
}

, , .

0

Source: https://habr.com/ru/post/1621346/


All Articles