Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Context
There is at least an issue of unclarity in the documentation around ecmaVersion
. I was running into a TypeError
which seemed to be a clash with eslint-plugin-react
, but ultimately turned out to be an issue of @typescript-eslint/parser evaluating to an unexpected ecmaVersion
.
This comment describing the problem lays out exactly what we discovered, but in short: I expected a string like es2020
to work as an appropriate ecmaVersion
value because the examples in the docs seem to indicate that this is an appropriate value, but ultimately this results in a real ecmaVersion
of es5
because the code is expecting a number and not a string.
I can, of course, simply use a number and move on, but I am curious how someone might use esnext
as a floating point, or if that's even a desired behavior. The way the code works now, one might just use a number like 5000
and expect that the parser will always use the esnext
version (at least in my lifetime), but that's certainly a hack more than a solution.
Repro
If you'd like to see the error happen, you can clone this repo which reproduces the problem.
.eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
ecmaFeatures: {
jsx: true,
modules: true,
},
ecmaVersion: "es2020",
tsconfigRootDir: __dirname,
project: `./tsconfig.json`,
},
settings: {
react: {
version: "detect",
},
},
};
hello.tsx
import React, { createContext } from "react";
const basicContext = { yes: "yes", no: "no" };
const AContext = createContext(basicContext);
export default (function () {
return (
<AContext.Provider value={basicContext}>
{/* put stuff in here if you want */}
</AContext.Provider>
);
} as React.FC);
tsconfig.json
{
"compilerOptions": {
"target": "ES2019",
"lib": ["dom", "dom.iterable", "ES2019"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"downlevelIteration": true,
"jsx": "react"
},
"include": ["*", "./.eslintrc.js"]
}
Expected Result
@typescript-eslint/parser uses the es2020
ecmaVersion
and does not end up causing errors in rules from other plugins.
Actual Result
@typescript-eslint/parser ultimately uses the es5
ecmaVersion
and causes errors in rules from eslint-plugin-react
.
Additional Info
This is the exception I ultimately see thrown (as can be seen in the linked repo above):
TypeError: Cannot read property 'variables' of null
Occurred while linting /Users/me/MacsideProjects/eslint-clash/hello.tsx:8
at checkIdentifierInJSX (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/lib/rules/jsx-no-undef.js:63:27)
at JSXOpeningElement (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/lib/rules/jsx-no-undef.js:106:9)
at /Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEventGenerator.applySelectors (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
at NodeEventGenerator.enterNode (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
at CodePathAnalyzer.enterNode (/Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
at /Users/me/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/linter.js:952:32
Here's the output with the --debug flag:
eslint:cli CLI args: [ '--debug', 'hello.tsx' ] +0ms
eslint:cli Running on files +5ms
eslintrc:config-array-factory Loading JSON config file: /Users/stevma/MacsideProjects/eslint-clash/package.json +0ms
eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/Users/stevma/MacsideProjects/eslint-clash', loose: false } ] +0ms
eslintrc:ignore-pattern processed: { basePath: '/Users/stevma/MacsideProjects/eslint-clash', patterns: [ '/**/node_modules/*' ] } +2ms
eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/Users/stevma/MacsideProjects/eslint-clash', loose: false } ] +0ms
eslintrc:ignore-pattern processed: { basePath: '/Users/stevma/MacsideProjects/eslint-clash', patterns: [ '/**/node_modules/*' ] } +1ms
eslint:file-enumerator Start to iterate files: [ 'hello.tsx' ] +0ms
eslint:file-enumerator File: /Users/stevma/MacsideProjects/eslint-clash/hello.tsx +1ms
eslintrc:cascading-config-array-factory Load config files for /Users/stevma/MacsideProjects/eslint-clash. +0ms
eslintrc:cascading-config-array-factory No cache found: /Users/stevma/MacsideProjects/eslint-clash. +0ms
eslintrc:config-array-factory Loading JS config file: /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +6ms
eslintrc:config-array-factory Config file found: /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +1ms
eslintrc:config-array-factory Loading {extends:"plugin:react/recommended"} relative to /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +0ms
eslintrc:config-array-factory Loading plugin "react" from /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +0ms
eslintrc:config-array-factory Loaded: eslint-plugin-react@7.21.5 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js) +1ms
eslintrc:config-array-factory Plugin /Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js loaded in: 116ms +116ms
eslintrc:config-array-factory Loading plugin "react" from /Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js +1ms
eslintrc:config-array-factory Loaded: eslint-plugin-react@7.21.5 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js) +0ms
eslintrc:config-array-factory Plugin /Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js loaded in: 0ms +0ms
eslintrc:config-array-factory Loading {extends:"plugin:@typescript-eslint/recommended"} relative to /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +0ms
eslintrc:config-array-factory Loading plugin "@typescript-eslint" from /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +1ms
eslintrc:config-array-factory Loaded: @typescript-eslint/eslint-plugin@4.11.0 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +0ms
eslintrc:config-array-factory Plugin /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 394ms +394ms
eslintrc:config-array-factory Loading {extends:"./configs/base"} relative to /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +0ms
eslintrc:config-array-factory package.json was not found: Cannot find module './configs/base/package.json'
Require stack:
- /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +0ms
eslintrc:config-array-factory Loaded: ./configs/base (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js) +0ms
eslintrc:config-array-factory Loading JS config file: /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js +1ms
eslintrc:config-array-factory Loading parser "@typescript-eslint/parser" from /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js +1ms
eslintrc:config-array-factory Loaded: @typescript-eslint/parser@4.11.0 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/parser/dist/index.js) +0ms
eslintrc:config-array-factory Loading plugin "@typescript-eslint" from /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js +80ms
eslintrc:config-array-factory Loaded: @typescript-eslint/eslint-plugin@4.11.0 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +0ms
eslintrc:config-array-factory Plugin /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 0ms +0ms
eslintrc:config-array-factory Loading {extends:"./configs/eslint-recommended"} relative to /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +1ms
eslintrc:config-array-factory package.json was not found: Cannot find module './configs/eslint-recommended/package.json'
Require stack:
- /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +0ms
eslintrc:config-array-factory Loaded: ./configs/eslint-recommended (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended.js) +0ms
eslintrc:config-array-factory Loading JS config file: /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended.js +0ms
eslintrc:config-array-factory Loading parser "@typescript-eslint/parser" from /Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js +3ms
eslintrc:config-array-factory Loaded: @typescript-eslint/parser@4.11.0 (/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/parser/dist/index.js) +0ms
eslintrc:cascading-config-array-factory Stop traversing because of 'root:true'. +602ms
eslint:rules Loading rule 'constructor-super' (remaining=283) +0ms
eslint:rules Loading rule 'getter-return' (remaining=282) +1ms
eslint:rules Loading rule 'no-const-assign' (remaining=281) +1ms
eslint:rules Loading rule 'no-dupe-args' (remaining=280) +0ms
eslint:rules Loading rule 'no-dupe-class-members' (remaining=279) +1ms
eslint:rules Loading rule 'no-dupe-keys' (remaining=278) +1ms
eslint:rules Loading rule 'no-func-assign' (remaining=277) +0ms
eslint:rules Loading rule 'no-import-assign' (remaining=276) +1ms
eslint:rules Loading rule 'no-new-symbol' (remaining=275) +0ms
eslint:rules Loading rule 'no-obj-calls' (remaining=274) +0ms
eslint:rules Loading rule 'no-redeclare' (remaining=273) +1ms
eslint:rules Loading rule 'no-setter-return' (remaining=272) +1ms
eslint:rules Loading rule 'no-this-before-super' (remaining=271) +0ms
eslint:rules Loading rule 'no-undef' (remaining=270) +1ms
eslint:rules Loading rule 'no-unreachable' (remaining=269) +0ms
eslint:rules Loading rule 'no-unsafe-negation' (remaining=268) +1ms
eslint:rules Loading rule 'no-var' (remaining=267) +1ms
eslint:rules Loading rule 'prefer-const' (remaining=266) +1ms
eslint:rules Loading rule 'prefer-rest-params' (remaining=265) +2ms
eslint:rules Loading rule 'prefer-spread' (remaining=264) +1ms
eslint:rules Loading rule 'valid-typeof' (remaining=263) +0ms
eslint:rules Loading rule 'no-array-constructor' (remaining=262) +6ms
eslint:rules Loading rule 'no-empty-function' (remaining=261) +0ms
eslint:rules Loading rule 'no-extra-semi' (remaining=260) +3ms
eslint:rules Loading rule 'no-unused-vars' (remaining=259) +2ms
eslintrc:cascading-config-array-factory Configuration was determined: ConfigArray(7) [ { type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '/Users/stevma/MacsideProjects/eslint-clash', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js » plugin:react/recommended', filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/index.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: { ecmaFeatures: [Object] }, plugins: { react: [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 'react/display-name': 2, 'react/jsx-key': 2, 'react/jsx-no-comment-textnodes': 2, 'react/jsx-no-duplicate-props': 2, 'react/jsx-no-target-blank': 2, 'react/jsx-no-undef': 2, 'react/jsx-uses-react': 2, 'react/jsx-uses-vars': 2, 'react/no-children-prop': 2, 'react/no-danger-with-children': 2, 'react/no-deprecated': 2, 'react/no-direct-mutation-state': 2, 'react/no-find-dom-node': 2, 'react/no-is-mounted': 2, 'react/no-render-return-value': 2, 'react/no-string-refs': 2, 'react/no-unescaped-entities': 2, 'react/no-unknown-property': 2, 'react/no-unsafe': 0, 'react/prop-types': 2, 'react/react-in-jsx-scope': 2, 'react/require-render-return': 2 }, settings: undefined }, { type: 'config', name: '.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/base', filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/parser/dist/index.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/base', importerPath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.js' }, parserOptions: { sourceType: 'module' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/eslint-recommended', filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/eslint-recommended#overrides[0]', filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended.js', criteria: { includes: [Array], excludes: null, basePath: '/Users/stevma/MacsideProjects/eslint-clash' }, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 'constructor-super': 'off', 'getter-return': 'off', 'no-const-assign': 'off', 'no-dupe-args': 'off', 'no-dupe-class-members': 'off', 'no-dupe-keys': 'off', 'no-func-assign': 'off', 'no-import-assign': 'off', 'no-new-symbol': 'off', 'no-obj-calls': 'off', 'no-redeclare': 'off', 'no-setter-return': 'off', 'no-this-before-super': 'off', 'no-undef': 'off', 'no-unreachable': 'off', 'no-unsafe-negation': 'off', 'no-var': 'error', 'prefer-const': 'error', 'prefer-rest-params': 'error', 'prefer-spread': 'error', 'valid-typeof': 'off' }, settings: undefined }, { type: 'config', name: '.eslintrc.js » plugin:@typescript-eslint/recommended', filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/eslint-plugin/dist/index.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/ban-ts-comment': 'error', '@typescript-eslint/ban-types': 'error', '@typescript-eslint/explicit-module-boundary-types': 'warn', 'no-array-constructor': 'off', '@typescript-eslint/no-array-constructor': 'error', 'no-empty-function': 'off', '@typescript-eslint/no-empty-function': 'error', '@typescript-eslint/no-empty-interface': 'error', '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-extra-non-null-assertion': 'error', 'no-extra-semi': 'off', '@typescript-eslint/no-extra-semi': 'error', '@typescript-eslint/no-inferrable-types': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', '@typescript-eslint/no-non-null-assertion': 'warn', '@typescript-eslint/no-this-alias': 'error', 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'warn', '@typescript-eslint/no-var-requires': 'error', '@typescript-eslint/prefer-as-const': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', '@typescript-eslint/triple-slash-reference': 'error' }, settings: undefined }, { type: 'config', name: '.eslintrc.js', filePath: '/Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js', criteria: null, env: { browser: true, node: true }, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/parser/dist/index.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.js', importerPath: '/Users/stevma/MacsideProjects/eslint-clash/.eslintrc.js' }, parserOptions: { sourceType: 'module', ecmaFeatures: [Object], ecmaVersion: 'es2018', tsconfigRootDir: '/Users/stevma/MacsideProjects/eslint-clash', project: './tsconfig.json' }, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: true, rules: undefined, settings: { react: [Object] } } ] on /Users/stevma/MacsideProjects/eslint-clash +40ms
eslintrc:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/Users/stevma/MacsideProjects/eslint-clash', loose: false } ] +657ms
eslintrc:ignore-pattern processed: { basePath: '/Users/stevma/MacsideProjects/eslint-clash', patterns: [ '/**/node_modules/*' ] } +1ms
eslintrc:ignore-pattern Check {
filePath: '/Users/stevma/MacsideProjects/eslint-clash/hello.tsx',
dot: false,
relativePath: 'hello.tsx',
result: false
} +1ms
eslint:cli-engine Lint /Users/stevma/MacsideProjects/eslint-clash/hello.tsx +0ms
eslint:linter Linting code for /Users/stevma/MacsideProjects/eslint-clash/hello.tsx (pass 1) +0ms
eslint:linter Verify +0ms
eslint:linter With ConfigArray: /Users/stevma/MacsideProjects/eslint-clash/hello.tsx +1ms
eslint:linter An error occurred while traversing +2s
eslint:linter Filename: /Users/stevma/MacsideProjects/eslint-clash/hello.tsx +0ms
eslint:linter Line: 8 +0ms
eslint:linter Parser Options: {
ecmaFeatures: { globalReturn: false, jsx: true, modules: true },
sourceType: 'module',
ecmaVersion: 'es2018',
tsconfigRootDir: '/Users/stevma/MacsideProjects/eslint-clash',
project: './tsconfig.json'
} +0ms
eslint:linter Parser Path: /Users/stevma/MacsideProjects/eslint-clash/node_modules/@typescript-eslint/parser/dist/index.js +0ms
eslint:linter Settings: { react: { version: 'detect' } } +0ms
Oops! Something went wrong! :(
ESLint: 7.16.0
TypeError: Cannot read property 'variables' of null
Occurred while linting /Users/stevma/MacsideProjects/eslint-clash/hello.tsx:8
at checkIdentifierInJSX (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/lib/rules/jsx-no-undef.js:63:27)
at JSXOpeningElement (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint-plugin-react/lib/rules/jsx-no-undef.js:106:9)
at /Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEventGenerator.applySelectors (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
at NodeEventGenerator.enterNode (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
at CodePathAnalyzer.enterNode (/Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
at /Users/stevma/MacsideProjects/eslint-clash/node_modules/eslint/lib/linter/linter.js:952:32
Versions
package | version |
---|---|
@typescript-eslint/parser |
4.11.0 |
TypeScript |
4.1.3 |
ESLint |
7.16.0 |
node |
15.4.0 |