eslint-config-preact': Cannot find module 'eslint-plugin-jest'
I created a new preact project using the cli npx preact-cli create typescript my-project
I tried to enable ESLint in my IDE (Webstorm) and receive the following error upon lint
Error Log:
Error: Failed to load plugin 'jest' declared in '--config » eslint-config-preact': Cannot find module 'eslint-plugin-jest'
Require stack:
- /Users/ben/projects/preact-template/__placeholder__.js
Referenced from: /Users/ben/projects/preact-template/node_modules/eslint-config-preact/dist/eslint-config-preact.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.resolve (node:internal/modules/cjs/helpers:108:19)
at Object.resolve (/Users/ben/projects/preact-template/node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
at ConfigArrayFactory._loadPlugin (/Users/ben/projects/preact-template/node_modules/eslint/lib/cli-engine/config-array-factory.js:959:39)
at ConfigArrayFactory._loadExtendedPluginConfig (/Users/ben/projects/preact-template/node_modules/eslint/lib/cli-engine/config-array-factory.js:779:29)
at ConfigArrayFactory._loadExtends (/Users/ben/projects/preact-template/node_modules/eslint/lib/cli-engine/config-array-factory.js:725:29)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/Users/ben/projects/preact-template/node_modules/eslint/lib/cli-engine/config-array-factory.js:660:25)
at _normalizeObjectConfigDataBody.next (<anonymous>)
at ConfigArrayFactory._normalizeObjectConfigData (/Users/ben/projects/preact-template/node_modules/eslint/lib/cli-engine/config-array-factory.js:596:20)
at _normalizeObjectConfigData.next (<anonymous>)
Process finished with exit code -1
.eslintrc.json
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"preact",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": [
"build/"
]
}
devDependencies
"devDependencies": {
"@quickbaseoss/babel-plugin-styled-components-css-namespace": "^1.0.1",
"@types/enzyme": "^3.10.5",
"@types/jest": "^26.0.8",
"@types/styled-components": "^5.1.15",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"babel-plugin-styled-components": "^2.0.1",
"enzyme": "^3.11.0",
"enzyme-adapter-preact-pure": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-preact": "^1.2.0",
"jest": "^27.2.5",
"jest-preset-preact": "^4.0.2",
"preact-cli": "^3.0.0",
"sirv-cli": "^1.0.0-next.3",
"typescript": "^3.7.5"
},
Sorry for the late response, hopefully you found a fix but you'd probably just need to do a clean install. eslint-plugin-jest is most certainly labeled as a dependency and should get dragged in on install of this config.
https://github.com/preactjs/eslint-config-preact/blob/c1edecaf3e57c844d03464bd48353ca10f782290/package.json#L54
Looks like this is a longstanding bug in eslint itself https://github.com/eslint/eslint/issues/3458
Assuming this is related? Getting this error after bumping to 1.3.0, looks like this possibly broke with https://github.com/jest-community/eslint-plugin-jest/pull/970 but I haven't investigated too deeply. Adding jest itself as a devDependency silences it for now if anybody needs a quick fix, even though I don't use it. :)
$ run-s lint:**
$ eslint .
Oops! Something went wrong! :(
ESLint: 8.4.1
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/jake/source/jarv.is/api/contact.js
at detectJestVersion (/Users/jake/source/jarv.is/node_modules/eslint-plugin-jest/lib/rules/detectJestVersion.js:26:9)
at create (/Users/jake/source/jarv.is/node_modules/eslint-plugin-jest/lib/rules/no-deprecated-functions.js:43:314)
at Object.create (/Users/jake/source/jarv.is/node_modules/@typescript-eslint/experimental-utils/dist/eslint-utils/RuleCreator.js:42:20)
[...]
Full logs: https://github.com/jakejarvis/jarv.is/runs/4549398177?check_suite_focus=true#step:6:1
Same for me, after bumping to 1.3.0. I don't use jest and prefer not to install it.
Other workaround is to add jest version to .eslintrc.json:
{
"root": true,
"extends": [
"preact"
],
"settings": {
"jest": { "version": 27 }
}
}
Same as @piotr-cz . Thank you for the workaround. I'm using another test runner. I hope to see a proper fix soon.
Other workaround is to disable this rule by adding:
"rules": { "jest/no-deprecated-functions": 0 }
I have some similar issues, but using eslint_d.
Everything seems fine with eslint, but for something breaks with eslint_d:
Error: Failed to load plugin 'jest' declared in '.eslintrc.json » eslint-config-preact': Cannot find module 'eslint'
I feel like this is somehow related.