Babel-eslint: Upgrading from 8.2.6 to 10.0.1 leads to lots of errors: Cannot read property 'range' of null

Created on 14 Jan 2019  路  17Comments  路  Source: babel/babel-eslint

Node: 10.13.0
eslint: 5.12.0
babel: 7.2.2

If I upgrade from 8.2.6 to 10.0.1 and then run the linter, lots of new errors (in the linter itself) start appearing. They all seem to look like this:

TypeError: Cannot read property 'range' of null
    at SourceCode.getTokenBefore (...\node_modules\eslint\lib\token-store\index.js:303:18)
    at checkSpacingBefore (...\node_modules\eslint\lib\rules\template-curly-spacing.js:54:42)
    at TemplateElement (...\node_modules\eslint\lib\rules\template-curly-spacing.js:119:17)
    at listeners.(anonymous function).forEach.listener (...\node_modules\eslint\lib\util\safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (...\node_modules\eslint\lib\util\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (...\node_modules\eslint\lib\util\node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (...\node_modules\eslint\lib\util\node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (...\node_modules\eslint\lib\util\node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (...\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:632:23)

I can't tell which files are causing this because that information isn't in the output. Still, I'd like to help out, so let me know if you need more information from me.

Most helpful comment

works for me

    "rules": {
      "indent": [
        "error",
        2,
        {
          "ignoredNodes": [
            "TemplateLiteral"
          ]
        }
      ],
      "template-curly-spacing": [
        "off"
      ]
    },

All 17 comments

Hey im having the same issue is there any fix for this?

A solution I came up with (which is as hacky as it can be, but hey, don't judge me) - is to regenerate yarn.lock(which is just removing it and doing yarn install again)

Does this also occur with the latest prerelease version (11.0.0-beta.0)?

I had the same problem here... rm -rf node_modules and removing package-lock.json and npm i solved it as well.

The "clean install" approach (blowing away node_modules) does not fix the issue for me. I'm pretty sure there's a legitimate bug in the code somewhere.

@kaicataldo The crash isn't happening in that beta version, so it looks like you guys fixed it, but I'm seeing new (unrelated) issues. Our import order plugin is now getting triggered for some reason, possibly because comments (in the file being linted) are being stripped out. I won't dig into that though until there's an official babel-eslint release.

@kaiyoma Feel free to make issues. That kind of feedback is what we're looking for with this prerelease. Reading from the end user's config is a pretty big departure from what this project has done in the past.

babel-eslint: ^9.0.0
eslint: ^5.13.0

i was getting the same range of null issue trying to use this parser, and for whatever reason, deleting node_modules and yarn.lock and then reinstalling dependencies cleared up the issue.

i also changed the declared versions from static to caret style. which makes me think there's a small verison mismatch somewhere in the dependency tree.

I had to downgrade to the same version @worc post it. With babel-eslint ^10.0.1 wasn't working.

I tried remove node_modules, package-lock.json and install all dependencies again, didn't work either.

I have same package-lock.json without lockfile,
using npm install to get all dependencies, gets this range of null error,
using yarn to get all dependencies, it's all fine

using [email protected] and [email protected]
[email protected]

ps: looks like yarn resolve and install package somewhat different than npm.
pss: removing babel-plugin-component from my dependencies solve this problem. babel-plugin-component depends on a earlier version of @babel/types.

I'm facing this problem too and I solved it also by removing node_modules and regenerating yarn.lock. However regenerating the whole lockfile shouldn't be considered a viable choice, because it collides with the concept of a lockfile (and it also breaks my system at other places). Are there any other known solutions to this problem?

Back when I ran into this, I upgraded to the latest version 11 beta, and that solved this issue. Recently though, I started to run into a different problem with babel-eslint, and searching through issues revealed that dropping back down to version 10 was the solution, so now I'm running 10.0.3 and everything works.

I have the same issue

TypeError: Cannot read property 'range' of null
Occurred while linting E:\AQSC\fe\frontapp-vue-samples\src\store\modules\tpridmp\common\permission.js:7
    at SourceCode.getTokenBefore (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\token-store\index.js:303:18)
    at checkSpacingBefore (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\rules\template-curly-spacing.js:60:42)
    at TemplateElement (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\rules\template-curly-spacing.js:119:17)
    at listeners.(anonymous function).forEach.listener (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\util\safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\util\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\util\node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\util\node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\util\node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (E:\AQSC\fe\frontapp-vue-samples\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:632:23)
Process finished with exit code -1

works for me

    "rules": {
      "indent": [
        "error",
        2,
        {
          "ignoredNodes": [
            "TemplateLiteral"
          ]
        }
      ],
      "template-curly-spacing": [
        "off"
      ]
    },

@fangbinwei Thanks

I can confirm this is still an issue with 10.0.3. Removing node_modules or yarn.lock does not help. Upgrading to 11.0.0-beta2 _does_ help, but then you have to use a beta version...

The fix provided by @fangbinwei also works, but then you lose eslint for templates. Both the ignoredNodes and template-curly-spacing keys are required; if either one is missing, the error still repros.

Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.

Was this page helpful?
0 / 5 - 0 ratings