Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'length' of undefined in lib/rules/prop-types.js line 51 #9

Closed
lencioni opened this issue Mar 4, 2015 · 6 comments

Comments

@lencioni
Copy link
Collaborator

lencioni commented Mar 4, 2015

After upgrading from 1.3.0 to 1.4.1, I am getting this error message:

/path/to/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:51
        for (var i = 0, j = property.value.properties.length; i < j; i++) {
                                                     ^
TypeError: Cannot read property 'length' of undefined
    at /path/to/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:51:54
    at Array.forEach (native)
    at EventEmitter.ObjectExpression (/path/to/project/node_modules/eslint-plugin-react/lib/rules/prop-types.js:46:23)
    at EventEmitter.emit (events.js:117:20)
    at Controller.controller.traverse.enter (/path/to/project/node_modules/eslint/lib/eslint.js:683:25)
    at Controller.__execute (/path/to/project/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/path/to/project/node_modules/eslint/node_modules/estraverse/estraverse.js:495:28)
    at EventEmitter.module.exports.api.verify (/path/to/project/node_modules/eslint/lib/eslint.js:676:24)
    at processFile (/path/to/project/node_modules/eslint/lib/cli-engine.js:172:23)
    at /path/to/project/node_modules/eslint/lib/cli-engine.js:271:26
    at /path/to/project/node_modules/eslint/lib/util/traverse.js:61:17
@yannickcr
Copy link
Member

I'll have a look at it. Can you share the code that trigger this error?

@yannickcr yannickcr self-assigned this Mar 4, 2015
@yannickcr yannickcr added the bug label Mar 4, 2015
@lencioni
Copy link
Collaborator Author

lencioni commented Mar 4, 2015

I'll try to whittle it down. Might take a bit.

@lencioni
Copy link
Collaborator Author

lencioni commented Mar 4, 2015

Ah, it looks like it happens when I am defining an object outside of the component to hold the propTypes, and then assigning it to that variable.

Something like:

const myPropTypes = {
  ...
};

const MyComponent = React.createClass({
  propTypes: myPropTypes,

  ...
});

@yannickcr
Copy link
Member

Ok, I see. I can fix the crash but I am not sure how to check propTypes definition in this case. I need to figure that out.

@lencioni
Copy link
Collaborator Author

Even if I try disabling this rule for the affected file via /* eslint-disable react/prop-types */ or even /* eslint-disable */, I still see the crash. If I disable it via .eslintignore, the crash is avoided.

I've refactored my code so I don't need this anymore, but it would be nice to be able to at least disable this rule on a per-file basis using the comments.

@josiasds
Copy link

josiasds commented Dec 3, 2015

The same error is happening here: https://github.com/shakacode/react-webpack-rails-tutorial/blob/cd35765c0a0d1a755c30944b4879bc12ca8e8163/client/app/stores/commentsStore.js#L8

This fixes the error, but I don't know exactly why. Any ideas?

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

No branches or pull requests

3 participants