Skip to content

TypeError: Cannot read property 'type' of null (prop/variable of same name across components) #130

Closed
@Standard8

Description

I've just tried upgrading to 2.6.0 from 2.5.2, if I put this minimal test case in a jsx file, it is now causing eslint to completely fail:

var TestComp1 = React.createClass({
  propTypes: {
    messageList: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
  },

  render: function() {
    return null;
  }
});

var TestComp2 = React.createClass({
  render: function() {
    var messageList;

    return null;
  }
});

The error is:

/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:536
      if (node.init.type !== 'ThisExpression' || node.id.type !== 'ObjectPatte
                   ^
TypeError: Cannot read property 'type' of null
    at EventEmitter.VariableDeclarator (/usr/local/lib/node_modules/eslint-plugin-react/lib/rules/prop-types.js:536:20)
    at EventEmitter.emit (events.js:117:20)
    at Controller.controller.traverse.enter (/usr/local/lib/node_modules/eslint/lib/eslint.js:724:25)
    at Controller.__execute (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/usr/local/lib/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/usr/local/lib/node_modules/eslint/lib/eslint.js:717:24)
    at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:201:27)
    at processFile (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:226:12)
    at /usr/local/lib/node_modules/eslint/lib/cli-engine.js:322:26
    at walk (/usr/local/lib/node_modules/eslint/lib/util/traverse.js:81:9)

Commenting out the var messageList; is the only way of "fixing" it, I've tried some different variable names, but i seems to be the var that is triggering this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions