james murphy
james murphy

Reputation: 1785

ReactNative Eslint & Flow giving parsing error for 'const' keyword

Ive spent hours looking over existing posts to no avail. The keyword 'const' gives me the following 2 errors from ESLint & Flow:

'const' can only be used in a .ts file.

Parsing error: Unexpected token

Code is just basic

import React from 'react';
import { View } from 'react-native';
import { List, ListItem, CheckBox, Text } from 'react-native-elements';

export default class Profile extends React.Component {
  state = {
    checked: false,
  };

  const array = [];

  render() {
    return (
      <View style={{ backgroundColor: '#EFEFF4', flex: 1 }}>
        <Text

Im using vsCode with: Eslint, BabelJavascript and Flow plugin extensions

Below are my dev dependencies

"devDependencies": {
"babel-eslint": "^8.2.2",
"babel-jest": "22.4.1",
"babel-preset-flow": "^6.23.0",
"babel-preset-react-native": "4.0.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"jest": "22.4.2",
"prettier-eslint": "^8.8.1",
"react-test-renderer": "16.3.0-alpha.1"}

and here is my eslintrc

  "parser": "babel-eslint",
  "extends": "airbnb",
  "plugins": ["react", "jsx-a11y", "import"],
  "rules": {
    "linebreak-style": 0,
    "prefer-destructuring": 0,
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "react/prefer-stateless-function": 0,
    "no-use-before-define": 0,
    "no-console": 0}

...and my babelrc

{
  "presets": ["react-native", "flow"],
  "retainLines": true,
  "sourceMaps": true
}

Please help this is killing me!!!

Upvotes: 0

Views: 413

Answers (1)

james murphy
james murphy

Reputation: 1785

I had const inside the class instead of outside.

Aaahh...gotta love those rookie mistakes (even those that take half your weekend and should have been solved in a second)

Upvotes: 1

Related Questions