question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'substring' of undefined

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.5.1
  • Node Version: 10.16.0
  • npm Version: 6.11.2

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
{
  "extends": [
    "airbnb",
    "plugin:react/recommended",
    "prettier",
    "prettier/react"
  ],
  "parser": "babel-eslint",
  "plugins": [
    "react",
    "prettier"
  ],
  "env": {
    "jest": true,
    "browser": true
  },
  "globals": {
    "__ENV": true
  },
  "rules": {
    "prettier/prettier": "error",
    "no-underscore-dangle": "off",
    "no-plusplus": "off",
    "import/no-named-as-default-member": "off",
    "jsx-a11y/label-has-for":"off"
  },
  "settings": {
    "import/resolver": {
      "babel-module": {
        "root": ["./src"]
      }
    }
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import PropTypes from 'prop-types';
import React from 'react';

import {
  Padding,
  Card,
  FieldListView,
  Button
} from 'components-library';

import Icon from '../../icons/icon.svg';
import i18n from '../../locales/i18n';

import AnotherComponent from './AnotherComponent';

const i18nInstance = i18n.instance;

const Component = ({ prop1, prop2 }) => {
  const fields = [
    {
      name: i18nInstance.t('FIRST_VALUE'),
      value: prop1.firstValue
    },
    {
      name: i18nInstance.t('SECOND_VALUE'),
      value: prop1.secondValue
    }
  ];

  const buttons = (
    <div>
      <Button
        onClick={prop2}
        primary
        icon={<Icon style={{ width: '1.2rem', height: '1.2rem' }} />}
      >
        {i18nInstance.t('ANOTHER_STRING')}
      </Button>
    </div>
  );

  return (
    <Padding>
      <Card buttons={buttons}>
        <AnotherComponent prop1={prop1} />
        <hr />
        <div>
          <Card.Headline level={3}>
            {i18nInstance.t('YET_ANOTHER_STRING')}
          </Card.Headline>
          <FieldListView fields={fields} />
        </div>
      </Card>
    </Padding>
  );
};

AccountDetail.propTypes = {
  prop1: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
  prop2: PropTypes.func.isRequired
};

export default Component;
eslint . --fix --ext .jsx --ext .js --rule 'no-console: error'

What did you expect to happen? Linting finishes without errors

What actually happened? Please include the actual, raw output from ESLint. Got the following error:

TypeError: Cannot read property 'substring' of undefined
Occurred while linting path/to/component/Component.jsx:36
    at Object.fix (node_modules/eslint-plugin-react/lib/rules/jsx-curly-brace-presence.js:129:30)
    at normalizeFixes (node_modules/eslint/lib/linter/report-translator.js:176:28)
    at args (node_modules/eslint/lib/linter/report-translator.js:278:49)
    at Object.report (node_modules/eslint/lib/linter/linter.js:904:41)
    at reportUnnecessaryCurly (node_modules/eslint-plugin-react/lib/rules/jsx-curly-brace-presence.js:117:15)
    at lintUnnecessaryCurly (node_modules/eslint-plugin-react/lib/rules/jsx-curly-brace-presence.js:198:9)
    at JSXExpressionContainer (node_modules/eslint-plugin-react/lib/rules/jsx-curly-brace-presence.js:278:11)
    at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (node_modules/eslint/lib/linter/safe-emitter.js:45:38)

Are you willing to submit a pull request to fix this bug? Sure - if i would know what it is - would be more than happy to fix it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
ZeD3vcommented, Oct 1, 2019

Confirmed - rolling back eslint-plugin-react to version 7.14.3 - fixes the issue.

0reactions
pargacommented, Oct 1, 2019

I can also confirm that rolling back to version ~7.14.0 fixes the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'substring' of undefined in react
I am trying to shorten a string in a react component I got from an API call in react but I get TypeError:...
Read more >
Cannot read property 'substring' of undefined #296 - GitHub
node_modules/less-loader/dist/cjs.js): Cannot read property 'substring' of undefined in undefined (line undefined, column undefined) at ...
Read more >
Error "Cannot read property 'substring' of undefined" during ...
Error "Cannot read property 'substring' of undefined" during sorting unauthorized agents by Last communication date · Go to tab "Agents" -> "Unauthorized" ·...
Read more >
TypeError: Cannot read property 'substring' of undefined ...
it returns the error :TypeError: Cannot read property 'substring' of undefined. I understand some of the code used (I copy pasted it from...
Read more >
TypeError: Cannot read property 'substring' of undefined - Reddit
TypeError : Cannot read property 'substring' of undefined ... So, I'm making a discord bot, and when I try and do a command,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found