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] Environment key "jest/globals" is unknown #33955

Closed
Bardiamist opened this issue Jun 2, 2022 · 12 comments
Closed

[eslint-config] Environment key "jest/globals" is unknown #33955

Bardiamist opened this issue Jun 2, 2022 · 12 comments

Comments

@Bardiamist
Copy link
Contributor

Bardiamist commented Jun 2, 2022

Description

I use @react-native-community/eslint-config with TypeScript. After update "@typescript-eslint/eslint-plugin", "@typescript-eslint/parser", and "@typescript-eslint/typescript-estree" from "5.24.0" to "5.25.0" I have error

Oops! Something went wrong! :(

ESLint: 8.16.0

Error: .eslintrc.js » @react-native-community/eslint-config#overrides[2]:
        Environment key "jest/globals" is unknown

    at /Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2058:23
    at Array.forEach (<anonymous>)
    at ConfigValidator.validateEnvironment (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2052:34)
    at ConfigValidator.validateConfigArray (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2202:18)
    at CascadingConfigArrayFactory._finalizeConfigArray (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3947:23)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3753:21)
    at FileEnumerator._iterateFilesRecursive (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/eslint/lib/cli-engine/file-enumerator.js:446:49)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (/Users/bardiamist/Documents/my-proj/my-proj-mobile/node_modules/eslint/lib/cli-engine/file-enumerator.js:297:49)
    at iterateFiles.next (<anonymous>)
error Command failed with exit code 2.

Version

3.0.2

Output of npx react-native info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 8.97 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.15 - /opt/homebrew/bin/yarn
    npm: 8.9.0 - /opt/homebrew/bin/npm
    Watchman: 2022.05.30.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8512546
    Xcode: 13.4/13F17a - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

Use @react-native-community
Run yarn eslint .

Snack, code example, screenshot, or link to a repository

module.exports = {
  parser: "@typescript-eslint/parser",
  extends: [
    'plugin:@typescript-eslint/recommended',
    '@react-native-community',
    'airbnb',
  ],
  ...
};
@Bardiamist
Copy link
Contributor Author

Bardiamist commented Jun 2, 2022

Related issue typescript-eslint/typescript-eslint#5132

@Bardiamist
Copy link
Contributor Author

Looks fixed in typescript-eslint 5.27.1

@sacru2red
Copy link

sacru2red commented Jun 30, 2022

@Bardiamist

I don't understand.

I think @react-native-community/eslint-config project should upgrade @typescript-eslint packages,

@react-native-community/eslint-config package have dependencies

"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",

And you can say "just upgrade your project dependencies only"
But, there's another problem
React import React 'React' was used before it was defined

I wonder, here is managing package "@react-native-community/eslint-config"
https://github.com/facebook/react-native/tree/HEAD/packages/eslint-config-react-native-community#readme

I tried edit my project yarn.loack file, to @typescript-eslint/ libs to ^5.27.1
and it works

@sacru2red
Copy link

sacru2red commented Jun 30, 2022

@Bardiamist

I don't understand.

I think @react-native-community/eslint-config project should upgrade @typescript-eslint packages,

@react-native-community/eslint-config package have dependencies

"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",

And you can say "just update your project dependencies only" But, there's another problem React import React 'React' was used before it was defined

I wonder, here is managing package "@react-native-community/eslint-config" https://github.com/facebook/react-native/tree/HEAD/packages/eslint-config-react-native-community#readme

I tried edit my project yarn.loack file, to @typescript-eslint/ libs to ^5.27.1 and it works

@Bardiamist

I don't understand.

I think @react-native-community/eslint-config project should upgrade @typescript-eslint packages,

@react-native-community/eslint-config package have dependencies

"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",

And you can say "just upgrade your project dependencies only" But, there's another problem React import React 'React' was used before it was defined

I wonder, here is managing package "@react-native-community/eslint-config" https://github.com/facebook/react-native/tree/HEAD/packages/eslint-config-react-native-community#readme

I tried edit my project yarn.loack file, to @typescript-eslint/ libs to ^5.27.1 and it works

I don't know what's the better,
I decide to upgrade "@typescript-eslint/eslint-plugin", "@typescript-eslint/parser" in my project
and I should add eslint config to

'no-use-before-define': 'off',
 '@typescript-eslint/no-use-before-define': ['error', { variables: false }]

@megacherry
Copy link

I had the same error and what worked was yarn-deduplicate, see also this comment: #32181 (comment)

I think it's related.

@JDMathew
Copy link
Contributor

Updating jest in package.json fixed this for me

@Bardiamist
Copy link
Contributor Author

Bardiamist commented Nov 16, 2022

Problem appears often after some depencencies update

I fixing by next steps:

  1. Set in package.json version of @react-native-community/eslint-config to 2.0.0 (3.1.0 don't work)
  2. yarn
  3. Set version back to 3.2.0
  4. yarn

@PrgrmmrOleg
Copy link

Here is what helped me
npm i eslint-plugin-jest -D

More details here

@tonsnoei
Copy link

tonsnoei commented Mar 24, 2023

In my case I was missing the file: jest.config.js in the root of my project. I added it with the following contents:

module.exports = {
    preset: 'react-native',
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};

This solves the issue.

@martinezguillaume
Copy link
Contributor

martinezguillaume commented Aug 21, 2023

For me this command fix it...
yarn upgrade @typescript-eslint/eslint-plugin @typescript-eslint/parser
(with a rm -rf node_modules && yarn after)
It's a real pain these dependencies, you think you have the last version, but in your yarn.lock, you still have old subdependencies...
Remove yarn.lock can be a solution, but it's more a workaround than a real solution.

Moise-Kongolo added a commit to Moise-Kongolo/fullstack-hy2020.github.io that referenced this issue Jan 7, 2024
In the package.json, "lint" is lowercase instead of "Lint". So the command should be "npm run lint"

When I ran the command i encountered an error saying jest/globals not found. I found a fix on github.
facebook/react-native#33955
@murashki
Copy link

nvm use 16 helped me

@fdobre
Copy link

fdobre commented Sep 25, 2024

For me this error showed up at upgrading from RN 0.73.9 to 0.74.5,

I fixed it with updating in package.json the following 2 modules vrom v5 to v7:

-    "@typescript-eslint/eslint-plugin": "^5.40.1",
-    "@typescript-eslint/parser": "^5.40.1",
+    "@typescript-eslint/eslint-plugin": "^7.18.0",
+    "@typescript-eslint/parser": "^7.18.0",

antonis added a commit to getsentry/sentry-react-native that referenced this issue Oct 8, 2024
antonis added a commit to getsentry/sentry-react-native that referenced this issue Oct 16, 2024
* Updates RN to 0.75.4 in the sample app and E2E test

* Removes Flipper from iOS

* Fixes lint issue (see facebook/react-native#33955)

* enable corepack in testflight dependencies step

* Sets the newArchEnabled=false for legacy builds

* enable corepack in testflight build step

* Enable corepack in a separate step

* Removes corepack step

* Updates OnLoad.cpp and CMakeList.txt to match the RN version samples

* Enable corepack and remove cache check

* Reverts CMakeLists.txt change

* Update yarn cache in testflight build

* Updates PrivacyInfo

* misc(ci): Remove unused testflight node_modules cache (#4178)

---------

Co-authored-by: LucasZF <[email protected]>
Co-authored-by: Krystof Woldrich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants