vscode-eslint: Unable to detect Jest version in create-react-app project
Iβm using create-react-app v4.0.1.
Error Log:
[Info - 11:26:57 AM] ESLint server is starting
[Info - 11:26:57 AM] ESLint server running in node v12.14.1
[Info - 11:26:57 AM] ESLint server is running.
[Info - 11:26:58 AM] ESLint library loaded from: /Users/me/source/spellbot/dash/node_modules/eslint/lib/api.js
[Error - 11:27:00 AM] ESLint stack trace:
[Error - 11:27:00 AM] Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly
Occurred while linting /Users/me/source/spellbot/dash/src/App.tsx
at detectJestVersion (/Users/me/source/spellbot/dash/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:38:9)
at create (/Users/me/source/spellbot/dash/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:61:256)
at Object.create (/Users/me/source/spellbot/dash/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/RuleCreator.js:13:24)
at createRuleListeners (/Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:761:21)
at /Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:931:31
at Array.forEach (<anonymous>)
at runRules (/Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:876:34)
at Linter._verifyWithoutProcessors (/Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:1173:31)
at Linter._verifyWithConfigArray (/Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:1271:21)
at Linter.verify (/Users/me/source/spellbot/dash/node_modules/eslint/lib/linter/linter.js:1226:25)
tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
.eslintrc.js:
module.exports = {
extends: [
'airbnb-typescript',
'airbnb/hooks',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
plugins: ['react', '@typescript-eslint', 'jest'],
env: {
browser: true,
es6: true,
jest: true,
},
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
project: './dash/tsconfig.json',
},
rules: {
'semi': ['error', 'never'],
'linebreak-style': 'off',
'prettier/prettier': ['error', {
endOfLine: 'auto',
'semi': false,
}],
},
};
package.json:
{
"name": "dash",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.14",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.6",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write src/**/*.ts{,x}",
"lint": "tsc --noEmit && eslint src/**/*.ts{,x}"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "^12.0.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "4.0.0",
"prettier": "^2.2.1"
}
}
settings.json:
{
[...]
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.formatOnSave": false,
"eslint.codeAction.disableRuleComment": { "enable": true, "location": "separateLine" },
"eslint.codeAction.showDocumentation": { "enable": true },
"eslint.codeActionsOnSave.mode": "all",
"eslint.format.enable": false,
"eslint.lintTask.enable": false,
"eslint.lintTask.options": ".",
"eslint.migration.2_x": "on",
"eslint.trace.server": "off",
[...]
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 17 (6 by maintainers)
Commits related to this issue
- eslint: Specify Jest version in config. This fixes a problem where format-on-save had stopped working for me, probably after updating vscode-eslint. I'd been getting this error: ``` Error: Error whi... — committed to chrisbobbe/zulip-mobile by chrisbobbe 3 years ago
- eslint: Specify Jest version in config. This fixes a problem where format-on-save had stopped working for me, probably after updating vscode-eslint. I'd been getting this error: ``` Error: Error whi... — committed to chrisbobbe/zulip-mobile by chrisbobbe 3 years ago
- fix: lint settings Related https://github.com/microsoft/vscode-eslint/issues/1145 — committed to nain93/react-native-kakao-login by hyochan 2 years ago
You can define this in the root of you eslint config:
It fixed it for me. EDIT: Change
26to you jest version.@lexicalunit this can very likely be addressed using the
eslint.workingDirectoriessetting. If in the terminal you need to change directory into the sub directory you need to let VS Code now about this. By default VS Code executes ESLint in the workspace folder root.@dbaeumer Powerβs back on and I was able to quickly test this. It works! π
I added the following to my
.eslintrc.jsfile in the react appβs root, which is a subdirectory off the root of my repository:And now when I open up the root of the repository in vscode my eslint plugin seems to work just fine.
Full context and solution for anyone else who has this issue:
From the root of my repository I have a Python project and then a subdirectory which contains my react application.
And my
dash/.eslintrc.jscontains:My
dash/.prettierrccontains:And the relevant parts of my
dash/package.jsoninclude:And in my vscode I have the following relevant settings changes from the default:
My installed vscode extensions include:
dbaeumer.vscode-eslintesbenp.prettier-vscodeHookyQR.beautifymgmcdermott.vscode-language-babelmike-co.import-sortermohsen1.prettify-jsonrichie5um2.vscode-sort-jsonGuys, Itβs missing to Jest a devDependencie, that was the fix on my end
npm install --save-dev jestESLint has many ways to store configurations including package.json files. So simply looking for eslintrc might not be good enough.
There is an auto mode for the
eslint.workingDirectorieswhich does some probing but might not work in all cases. Auto is not the default since it might break exising users relying on a different working directory to resolve the ignore file.