Skip to content
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

eslint-config-preact': Cannot find module 'eslint-plugin-jest' #19

Open
bendgk opened this issue Nov 25, 2021 · 7 comments · May be fixed by #25
Open

eslint-config-preact': Cannot find module 'eslint-plugin-jest' #19

bendgk opened this issue Nov 25, 2021 · 7 comments · May be fixed by #25

Comments

@bendgk
Copy link

bendgk commented Nov 25, 2021

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"
  },
@rschristian
Copy link
Member

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.

"eslint-plugin-jest": "^23.7.0",

@marvinhagemeister
Copy link
Member

Looks like this is a longstanding bug in eslint itself eslint/eslint#3458

@jakejarvis
Copy link

jakejarvis commented Dec 16, 2021

Assuming this is related? Getting this error after bumping to 1.3.0, looks like this possibly broke with jest-community/eslint-plugin-jest#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

@piotr-cz
Copy link

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 }
  }
}

@dolie
Copy link

dolie commented Oct 21, 2022

Same as @piotr-cz . Thank you for the workaround.
I'm using another test runner. I hope to see a proper fix soon.

@julienw
Copy link

julienw commented Jan 14, 2023

Other workaround is to disable this rule by adding:

    "rules": { "jest/no-deprecated-functions": 0 }

@zArubaru
Copy link

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.

ihch pushed a commit to ihch/dayta that referenced this issue Jul 24, 2023
eslint-config-preactがjestの設定に依存していて、その中のひとつがjestのバージョンを読もうとする。
今回は入れないのでdisableにする。
preactjs/eslint-config-preact#19
jest-community/eslint-plugin-jest#686
KamilaBorowska added a commit to KamilaBorowska/eslint-config-preact that referenced this issue Dec 27, 2023
ESLint documentation says the following:

> If your shareable config depends on a plugin, you should also specify
> it as a peerDependency (plugins will be loaded relative to the end
> user's project, so the end user is required to install the plugins
> they need).

Fixes preactjs#19.
@KamilaBorowska KamilaBorowska linked a pull request Dec 27, 2023 that will close this issue
KamilaBorowska added a commit to KamilaBorowska/eslint-config-preact that referenced this issue Dec 27, 2023
ESLint documentation says the following:

> If your shareable config depends on a plugin, you should also specify
> it as a peerDependency (plugins will be loaded relative to the end
> user's project, so the end user is required to install the plugins
> they need).

Fixes preactjs#19.
KamilaBorowska added a commit to KamilaBorowska/eslint-config-preact that referenced this issue Dec 27, 2023
ESLint documentation says the following:

> If your shareable config depends on a plugin, you should also specify
> it as a peerDependency (plugins will be loaded relative to the end
> user's project, so the end user is required to install the plugins
> they need).

Fixes preactjs#19.
sclaret added a commit to sclaret/website that referenced this issue Jan 24, 2024
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

 preactjs/eslint-config-preact#19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants