Eslint-plugin-react: TypeError: Cannot read property 'toLowerCase' of undefined in jsx-no-target-blank

Created on 13 Sep 2016  路  18Comments  路  Source: yannickcr/eslint-plugin-react

As of https://github.com/yannickcr/eslint-plugin-react/commit/fa99e13629c025d46220d0b57fecbe5823320f4f#diff-05dfa6b555ee6724cba772b5d07e4d1c, installing eslint/eslint-plugin-react with

npm install eslint eslint-plugin-react

and running the following eslint command in Codeship...

node_modules/eslint/bin/eslint.js -c .eslintrc --ext .jsx,.js path/to/code

is resulting in:

Cannot read property 'toLowerCase' of 
TypeError: Cannot read property 'toLowerCase' of undefined
at EventEmitter.JSXAttribute (/home/rof/src/github.com/newsela/newsela/node_modules/eslint-plugin-react/lib/rules/jsx-no-target-blank.js:28:60)
at emitOne (events.js:82:20)
at EventEmitter.emit (events.js:169:7)
at NodeEventGenerator.enterNode (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/lib/util/node-event-generator.js:40:22)
at CodePathAnalyzer.enterNode (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
at CommentEventGenerator.enterNode (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
at Controller.enter (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/lib/eslint.js:918:36)
at Controller.__execute (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
at Controller.traverse (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/node_modules/estraverse/estraverse.js:501:28)
at Controller.Traverser.controller.traverse (/home/rof/src/github.com/newsela/newsela/node_modules/eslint/lib/util/traverser.js:36:33)

To be clear, this seems to be _only_ happening on Codeship. We've temporarily solved this by commenting out the offending rule (jsx-no-target-blank). Is this something others are seeing or should I bring this up with Codeship instead?

bug

Most helpful comment

Working on a fix.

All 18 comments

What version of node does codeship run?

Same problem.

Cannot read property 'toLowerCase' of undefined
TypeError: Cannot read property 'toLowerCase' of undefined
    at EventEmitter.JSXAttribute (/Users/myabc/git/myproj/node_modules/eslint-plugin-react/lib/rules/jsx-no-target-blank.js:28:60)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.enterNode (/Users/myabc/git/myproj/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/Users/myabc/git/myproj/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (/Users/myabc/git/myproj/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (/Users/myabc/git/myproj/node_modules/eslint/lib/eslint.js:918:36)
    at Controller.__execute (/Users/myabc/git/myproj/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/Users/myabc/git/myproj/node_modules/estraverse/estraverse.js:501:28)
    at Controller.Traverser.controller.traverse (/Users/myabc/git/myproj/node_modules/eslint/lib/util/traverser.js:36:33)

Version:

    "eslint": "^3.3.0",
    "eslint-config-airbnb": "^11.1.0",
    "eslint-plugin-babel": "^3.3.0",
    "eslint-plugin-import": "^1.14.0",
    "eslint-plugin-jsx-a11y": "^2.2.2",
    "eslint-plugin-react": "^6.2.1",

@kouhin as i commented in the other issue, your versions are incompatible - npm ls should be complaining, because you need eslint v3.5 with eslint-config-airbnb v11.1.

@chalisegrogan what versions of eslint everything is in your package.json?

I'm getting this error with [email protected] and [email protected]. Yesterday it wasn't manifesting.

EDIT: I'm not using codeship

I can't help myself to create this repository https://github.com/kouhin/eslint-config-airbnb-deps

npm install eslint-config-airbnb-deps --save-dev

Currently I'm using npm install [email protected] --save-dev

Everything works well. 馃槈

@kouhin Thanks, this leads me on the right track. eslint-config-airbnb-deps uses the 6.2.0.

The error has been introduce with 6.2.1.

I suggest updating your package.json to use the 6.2.0.

Just ran into the same problem (TypeError: Cannot read property 'toLowerCase' of undefined) with 6.2.1. Switching to 6.2.0 works.

"eslint": "^3.5.0",
"eslint-config-airbnb": "^11.1.0",
"eslint-plugin-import": "^1.15.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "6.2.0",

This is a simple component that triggers the error

import React, { PropTypes } from 'react';

export default function Foo() {
    const targetValue = '_blank';

    return (
        <a target={targetValue}>bar</a>
    );
};
Cannot read property 'toLowerCase' of undefined
TypeError: Cannot read property 'toLowerCase' of undefined
    at EventEmitter.JSXAttribute (/var/www/test/node_modules/eslint-plugin-react/lib/rules/jsx-no-target-blank.js:28:60)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:169:7)
    at NodeEventGenerator.enterNode (/var/www/test/node_modules/eslint/lib/util/node-event-generator.js:40:22)
    at CodePathAnalyzer.enterNode (/var/www/test/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at CommentEventGenerator.enterNode (/var/www/test/node_modules/eslint/lib/util/comment-event-generator.js:97:23)
    at Controller.enter (/var/www/test/node_modules/eslint/lib/eslint.js:918:36)
    at Controller.__execute (/var/www/test/node_modules/eslint/node_modules/estraverse/estraverse.js:397:31)
    at Controller.traverse (/var/www/test/node_modules/eslint/node_modules/estraverse/estraverse.js:501:28)
    at Controller.Traverser.controller.traverse (/var/www/test/node_modules/eslint/lib/util/traverser.js:36:33)

@ljharb Codeship is set up to run with: "node": "~4.2.2".

As for eslint, this was the package json at the time of running:

"eslint": "^2.12.0",
"eslint-loader": "^1.3.0",
"eslint-plugin-react": "^5.1.1",
"eslint-plugin-jsx-a11y": "^2.2.0",

_note:_ we're now specifically targeting "eslint-plugin-react": "6.2.0",

@chalisegrogan can you rerun it with all the latest of eslint, eslint-plugin-react, and eslint-plugin-jsx-a11y?

@ljharb set up as follows:

"eslint": "^3.5.0",
"eslint-plugin-react": "6.2.1",
"eslint-plugin-jsx-a11y": "^2.2.2",

is still failing with the same error.

@chalisegrogan and presumably if you lock eslint-plugin-react to 6.2.0, the error goes away?

@ljharb correct.

I'm guessing this was introduced by fa99e13629c025d46220d0b57fecbe5823320f4f. @dmnd any chance you can take a look at this?

Working on a fix.

Awesome, thank you @yannickcr !

+1

Was this page helpful?
0 / 5 - 0 ratings