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.

Template string failing with Cannot read property 'range' of null

See original GitHub issue

It throws error when dynamic import, template literal inline and rule template-curly-spacing as follow:

Tested on:

babel-eslint@10.0.3 (with @babel/parser@7.7.7) eslint@6.7.2

Sample code:

import(`${'package.json'}`)

.eslintrc.json

{
  "parser": "babel-eslint",
  "rules": {
    "template-curly-spacing": ["error", "never"]
  }
}

The problem is coming from @babel/parser@7.7.7, which added ImportExpression.

_Originally posted by @yitomok in https://github.com/babel/babel-eslint/issues/799#issuecomment-567598343_


Edits by @JLHwung

If you come across this issue from search engine, see below for the solution:

  1. uninstall babel-eslint
  2. install @babel/eslint-parser
  3. replace babel-eslint by @babel/eslint-parser in your ESLint config
  4. if you use eslint-plugin-babel, do 4.a - 4.c, otherwise skip it 4.a uninstall eslint-plugin-babel 4.b install @babel/eslint-plugin 4.c replace "babel" or "eslint-plugin-babel" to "@babel"
  5. The working ESLint config should look like https://github.com/babel/babel/issues/10904#issuecomment-691827355

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:60
  • Comments:28 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
rjgottencommented, Nov 19, 2020

FYI; This is still broken.

package versions eslint@7.13.0 @babel/eslint-parser@7.12.1

Have to selectively disable ESLint rules to skirt the problem, like so:

"template-curly-spacing" : "off"

or ESLint still blows up with:

TypeError: Cannot read property 'value' of null
Occurred while linting [redacted]
    at checkSpacingBefore ([redacted]\node_modules\eslint\lib\rules\template-curly-spacing.js:52:24)
    at TemplateElement ([redacted]\node_modules\eslint\lib\rules\template-curly-spacing.js:136:17)
    at [redacted]\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit ([redacted]\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector ([redacted]\node_modules\eslint\lib\linter\node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors ([redacted]\node_modules\eslint\lib\linter\node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode ([redacted]\node_modules\eslint\lib\linter\node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode ([redacted]\node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:711:23)
    at [redacted]\node_modules\eslint\lib\linter\linter.js:952:32

Here, inside template-curly-spacing the sourceCode.getFirstToken call ends up returning null:

return {
  TemplateElement(node) {
    const token = sourceCode.getFirstToken(node);

    checkSpacingBefore(token);
    checkSpacingAfter(token);
  }
};

[EDIT]

Looks like this is STILL the problem with a wrong version of @babel/types being used. After a thorough wipe and reinstall of all things @babel (as npm dedup was deduping to the WRONG version) it does work.

I though the whole idea of having the eslint parser go into the mono repo was to maintain it together with Babel and prevent exactly that shitty issue?

8reactions
JLHwungcommented, Aug 8, 2020

Fixed in @babel/eslint-parser@7.11.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template string failing with Cannot read property 'range' of null
jsx I have template strings, it blows up with this error. TypeError: Cannot read property 'range' of null. This is my current list...
Read more >
eslint error cannot read property 'range' of null - Stack Overflow
My solution was to use yarn instead of npm. Has solved the problem for the time being. node-modules · eslint.
Read more >
ESLint: Cannot read property 'value' of null Occurred while ...
when dealing template string came out such error :ESLint: Cannot read property 'value' of null Occurred while linting /path/to/file.js:43.
Read more >
eslint/eslint - Gitter
I am having an issue with ESLint while deploying my react app to Heroku. I am getting this error "Oops! Something went wrong!...
Read more >
estlint -Cannot read property 'range' of null - 简书
编程风格要统一编程风格这个东西,说实在的对于刚加入团队的新成员来说还是很难让人完全适应的。因为每人的编程风格都不.
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