Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

warning 'state' is not defined. #529

Closed
n1c01a5 opened this issue Oct 15, 2017 · 17 comments
Closed

warning 'state' is not defined. #529

n1c01a5 opened this issue Oct 15, 2017 · 17 comments

Comments

@n1c01a5
Copy link

n1c01a5 commented Oct 15, 2017

I use this linter with react and standardjs but I have this warning (yarn lint) :

'state' is not defined.

How can I fix it?

@loganfsmyth
Copy link
Member

On what line of code? It sounds like it's giving you a valid warning, but you haven't shown any code so there's no way to address this.

@n1c01a5
Copy link
Author

n1c01a5 commented Oct 16, 2017

@lord-xeon
Copy link

I am now getting lint errors of no-undef for decorators, defaultProps, and state in my React Components.

import Autobind from "autobind-decorator";

...

export default class SomeClass extends React.Component {

    static defaultProps = {
        // initial properties
    };

    state = {
        // Some state
   };

    @Autobind
    onButtonClick(event){
        // Some function
    }
}

I'm using:

  • eslint v.3.19.0
  • babel-eslint v7.2.3
  • gulp-eslint v3.0.1

@zargold
Copy link

zargold commented Nov 27, 2017

I had gotten this error but now have fixed it here is my full eslint related devDependencies:

{
"devDependencies": {
    "babel-eslint": "^8.0.2",
    "eslint": "^4.12.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-flowtype": "2.39.1",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.5.1",
    "...": "...other stuff"
},
"eslintConfig": {
    "extends": [
      "airbnb",
      "standard",
      "standard-react"
    ],
    "parser": "babel-eslint",
    "plugins": [
      "babel",
      "react",
      "promise"
    ],
    "env": {
      "browser": true,
      "jest": true
    },

@lilrogalski
Copy link

I'm having the same issue, and its also happening with arrow methods, see my issue that I posted in the eslint issues here:

eslint/eslint#10302 (comment)

@ehmkah
Copy link

ehmkah commented Jul 24, 2018

Has this issue already been solved? I do not see/ understand the solution.

@lilrogalski
Copy link

@ehmkah I'm no longer having this issue, but my babel setup has changed significantly since then

@ehmkah
Copy link

ehmkah commented Jul 25, 2018

@ryanrogalski - ok maybe my configuration is too old. Hopeful this issue does not appear anymore update it. :-)

@abdul-stripe
Copy link

in my case, it was because i was using the babel-eslint parser without the babel eslint plugin

installing and including https://github.com/babel/eslint-plugin-babel fixed it

@robbporto
Copy link

robbporto commented Sep 5, 2018

Same problem here.

@muhaimincs
Copy link

can someone post full setup here

@rohan-deshpande
Copy link

rohan-deshpande commented Sep 22, 2018

Suddenly having this issue, nothing in my setup has changed. Relevant packages being used in devDependencies

    "babel-eslint": "^7.1.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "eslint": "^3.19.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^5.0.3",
    "eslint-plugin-react": "^7.0.1",

And here is my .eslintrc.json

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
      "eslint:recommended",
      "plugin:import/errors",
      "plugin:import/warnings"
    ],
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "globals":  {
      "process": true
    },
    "rules": {
        "indent": [
            "error",
            2,
            { "SwitchCase": 1 }
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ],
        "no-console": 0,
        "react/jsx-uses-react": 2,
        "react/jsx-uses-vars": 2,
        "react/react-in-jsx-scope": 2
    }
}

I tried using the babel plugin and installing eslint-plugin-babel as @abdul-stripe suggested, however as soon as I do that, I get another error

Error while running ESLint: eslint.Linter is not a constructor

Which gets thrown specifically in that package. Perhaps a version mismatch? I don't get it though, I never had to do this before. This just started happening all of a sudden. My guess is that someone put a breaking change in a minor package update somewhere...

Update: Have installed eslint-plugin-babel@4.1.2 and the above ESLint error is no longer getting thrown, but the original issue is not resolved.

Can everyone post what editor they are using? Perhaps it's related? I'm using Atom v1.30.0 with linter-eslint@8.4.1

Update 2: I've fixed the issue. I went through all my dependencies in my develop branch and compared them to my current feature branch and found that the only difference was react-scripts. I was using 1.0.7 previously and in my branch it had been upgraded to 1.1.5. Forcing my app to go back to react-scripts@1.0.7 fixed it for me. If you check the dependencies of this package, the required eslint version has gone from 3.19.0 to > 4. Seems like a breaking change to me, I they should have gone to 2.0.0.

So here are my final devDependencies

  "devDependencies": {
    "babel-eslint": "^7.1.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "eslint": "^3.19.0",
    "eslint-plugin-babel": "^4.1.2",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^5.0.3",
    "eslint-plugin-react": "^7.0.1",
    "import-sort-cli": "^3.3.0",
    "import-sort-parser-babylon": "^3.2.0",
    "import-sort-style-absolute": "^1.0.1",
    "madge": "^2.2.0",
    "node-sass": "^4.9.2",
    "react-scripts": "1.0.7"
  },

Make sure you check package-lock.json to be really sure that you are using the right version of all this stuff.

@robbporto
Copy link

@rohan-deshpande, I'm glad that you were able to fix but changing the version of react-scripts seems risky...

@rohan-deshpande
Copy link

rohan-deshpande commented Oct 2, 2018

@robbporto I didn't change it, it was ^1.0.7 before and running npm install bumped it to 1.1.5 because I had a ^ before the version and the minor upgrade broke all my stuff. Minor upgrades should not cause breaking changes. Reverting it back to 1.0.7 and locking it fixed things because my other dependencies were stable with that version of react-scripts

@croraf
Copy link

croraf commented Oct 7, 2018

Should be closed in favour of #487

@nour-s
Copy link

nour-s commented Nov 9, 2018

My solution was to add:
"babel-eslint": "^8.0.2"
To the dependencies list.

@kaicataldo
Copy link
Member

Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests