-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Template string failing with Cannot read property 'range' of null #10904
Comments
Hey @yitomok! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
I think this should be fixed by #10828, but will have to verify. |
Added to #10752 so I don't forget to verify this when I start going through rules. |
The following does not trigger the 'range' of null error:
but the following does:
|
What version are you using? |
Hey @kaicataldo,
|
@kaicataldo Relevant packages:
(NOTE: Problem actually occurs with Unlisted dependencies confirmed fully de-duped:
|
For reasons that are not entirely clear to me, recent versions of eslint break when trying to parse inline template literals. The issue can be tracked babel/babel#10904 Downgrading to an earlier version fixes the problem without causing other problems. Maybe by the time we need a more recent version they will have fixed the problem.
I am experiencing this problem when I lint code like this (string templates without any interpolation inside): this.box = `<div>
text line
</div>`; |
For reasons that are not entirely clear to me, recent versions of eslint break when trying to parse inline template literals. The issue can be tracked babel/babel#10904 Downgrading to an earlier version fixes the problem without causing other problems. Maybe by the time we need a more recent version they will have fixed the problem.
This should be fixed in the latest v11 prerelease (and will be included in the next major release, which will be under a new package name). |
Regarding the "latest v11 prerelease", I guess you mean the next such release, @kaicataldo, as npm is showing the latest release for |
when will this release? use 8.x babel-eslint will result in other bugs... |
The issue persists. Any workaround? Fixing the version to |
As mentioned here, I could get this to work using the |
Fixed with https://github.com/atlassian/yarn-deduplicate apparently in my case one package messes up dependency tree. |
"babel-eslint": "10.1.0" OR "@babel/eslint-parser": "^7.11.0", The I ran in to this particular issue with
The eslint doesn't throw the error if the optional chaining is removed from ☝️. A log at https://github.com/babel/babel-eslint/blob/10.x/lib/babylon-to-espree/toAST.js#L101 or https://github.com/babel/babel/blob/master/eslint/babel-eslint-parser/src/convert/convertAST.js#L64 to log the node object shows that the following node is missing when optional chaining is present.
I believe that these nodes are generated by the "@babel/parser" library. Is it possible that the issue is in the parser lib? |
It seems that defining defineType("ImportExpression", {
visitor: ["source"],
fields: {},
aliases: [],
}); |
@cdoublev |
|
Fixed in |
How should fix, upgrading packages?? |
Thanks @LexSwed, It seems that was the problem in my case as well. I needed to run |
Came here from eslint/eslint#13394. Could someone give me brief instructions on how to handle this fix, please? I'm aware of FOSS requiring some interest and time to spent to work with. I know it's about shared efforts. However, right now I'd like to use ESLint to check my own FOSS code. I have a basic understanding on what babel is and when to use it, but I don't know all the relations between all that babel-packages mentioned in this thread and how they are integrated with ESLint. Currently I'm quite little interested in studying those internals to get babel-eslint working as a parser in ESLint again. So, is there any easy way to fix that linked issue when trying to add babel-eslint to ESLint? |
Try switching to
https://babeljs.io/blog/2020/07/13/the-state-of-babel-eslint |
I found this minimum configuration helpful (with unrelated or too specific pieces removed): package.json {
"name": "your-project",
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/eslint-parser": "^7.11.5",
"@babel/eslint-plugin": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"eslint": "^7.9.0"
}
} .babelrc (required) {
"presets": [
[
"@babel/env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
},
"useBuiltIns": "usage",
"corejs": "3.6.4"
}
]
]
} .eslintrc {
"plugins": [
"@babel"
],
"extends": [
"your-preferred-ruleset-here"
],
"parser": "@babel/eslint-parser",
} |
FYI; This is still broken. package versions Have to selectively disable ESLint rules to skirt the problem, like so:
or ESLint still blows up with:
Here, inside
[EDIT] Looks like this is STILL the problem with a wrong version of 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? |
Upgrade eslint parser for having this bug fixed: babel/babel#10904
Upgrade eslint parser for having this bug fixed: babel/babel#10904
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:
.eslintrc.json
The problem is coming from
@babel/parser@7.7.7
, which addedImportExpression
.Originally posted by @yitomok in babel/babel-eslint#799 (comment)
Edits by @JLHwung
If you come across this issue from search engine, see below for the solution:
babel-eslint
@babel/eslint-parser
babel-eslint
by@babel/eslint-parser
in your ESLint configeslint-plugin-babel
, do 4.a - 4.c, otherwise skip it4.a uninstall
eslint-plugin-babel
4.b install
@babel/eslint-plugin
4.c replace
"babel"
or"eslint-plugin-babel"
to"@babel"
The text was updated successfully, but these errors were encountered: