react-native: Error: Failed to load plugin 'prettier' declared in '.eslintrc.js » @react-native-community/eslint-config': Cannot find module 'eslint-plugin-prettier' Require stack:

After installing react-native with npx it throws an error on me with eslint settings in webstorm.

Description

I have tried installing prettier on it’s own but it didn’t worked

React Native version: 0.65.1

Run react-native info in your terminal and copy the results here. info Fetching system and libraries information… System: OS: macOS 11.5.2 CPU: (8) arm64 Apple M1 Memory: 179.45 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.8.0 - /opt/homebrew/bin/node Yarn: Not Found npm: 7.21.0 - /opt/homebrew/bin/npm Watchman: 2021.08.30.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.0 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: Not Found IDEs: Android Studio: Arctic Fox 2020.3.1 Patch 2 Arctic Fox 2020.3.1 Patch 2 Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild Languages: Java: Not Found npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.65.1 => 0.65.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. npx react-native some
  2. open app in webstorm

Expected Results

Describe what you expected to happen. no errors is shown

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

Screenshot 2021-09-10 at 11 50 01 I haven't changed anything from the app created with npx

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 22 (1 by maintainers)

Most upvoted comments

For those using yarn, try npx yarn-deduplicate.

This is probably happening due to duplicate copies of certain libraries.

I think it’s all caused by peer dependency in npm >=7. In my case, installing dependencies in the old npm 4-6 mode helped, i.e.:

  1. Remove node_modules, package-lock.json
  2. npm install --legacy-peer-deps

Article about dependencies:

Ooookay, so to add to the confusion, I tried running the exact setup from @react-native-commnity/eslint-config on both Windows WSL2/Ubuntu (Node 16.6.0, NPM 7.20.6) and Mac (Node 16.7.0, NPM 7.20.3).

# Install dependencies
> npm install --save-dev eslint prettier @react-native-community/eslint-config

# Create ESLint file and copy in from NPM page
> touch .eslintrc

# Create simple TypeScript file with some to be caught by linter
> touch index.ts

# Add ESLint script and run
> npm run lint

For some unknown reason, this succeeded on Windows WSL2/Ubuntu, but failed on Mac! Exact same commands…everything 😱! At this point I am probably going to have to replace this package with the underlying packages, unless anyone has some ideas on why this is different between Linux and Mac. Also curious if anyone else can replicate this issue with the above workflow?

I should mention that running the linter by itself also throws this error (not just VSCode).

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-prettier".

(The package "eslint-plugin-prettier" was not found when loaded as a Node module from the directory "/Users/kendallroth/Development/payme".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

    npm install eslint-plugin-prettier@latest --save-dev

The plugin "eslint-plugin-prettier" was referenced from the config file in ".eslintrc.js » @react-native-community/eslint-config"

Installing as instructed/recommended that moves the error to a missing prettier config package.

ESLint: 7.32.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/Users/kendallroth/Development/payme/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js".

Installing eslint-config-prettier in turn mentions an issue with globals/jest.

ESLint: 7.32.0

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

as @SimonChaumet stated: “the package isn’t found because it is placed underneath @react-native-community/eslint-config instead of the root node_modules” this happens when there are multiple versions of prettier installed on your project (you can find them all in your yarn.lock by searching for “prettier@”)

For instance, a faulty yarn.lock:

prettier@^2.0.2:
  version "2.1.2"
  resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
  integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==

prettier@^2.5.1:
  version "2.5.1"
  resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
  integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==

The first line (v2.1.2) comes from @react-native-community/eslint-config, the second (v2.5.1) from my package.json

To make sure that only 1 version is installed:

  • ensure that all prettier requirements (the version in your package.json and the version of all libs using prettier) are compatible.
  • remove all the resolution line from your yarn.lock (these are the lines above)
  • run yarn again
  • check that it finished successfully, and that your yarn.lock file is updated:
prettier@^2.0.2, prettier@^2.5.1:
  version "2.5.1"
  resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
  integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==

for me, with rn 0.64.2 and @react-native-community/eslint-config@3.0.1 , when yarn install, i got the error:

error An unexpected error occurred: “could not find a copy of prettier to link in C:\code\tt\fatboy\node_modules\@react-native-community\eslint-config\node_modules”.

when changing @react-native-community/eslint-config@^2.0.0, i got no errors. It’s not a solution, but can bypass this problem temp.

I got the same error after upgrading a project from Node.js 14.18.1 to version 16.13.0. No other changes were made. Installing the aforementioned packages manually fixed the problem.

I have downgraded node from 16.13.0 to 14.18.1 to fix the issue. Do you think it’s better to manually install all the missing packages instead? (both are just a workaround for the broken default react-native project init on Mac)

i had the same probleme. i think there is a trouble with the path of dependency of this package. i fixed it by installing those and his dependencies manually : “eslint-config-prettier” “eslint-plugin-eslint-comments” “eslint-plugin-flowtype” “eslint-plugin-jest” “eslint-plugin-prettier” “prettier”

try to install the same version of packages, you can use npm ls <package_name> to get the version. and npm install -D <package_name>@<version> to install specific version.

don’t forget to delete package.lock and node_modules if you have some troubles. and don’t forget to restart vscode after package installation to allow eslint server to restart.

I can verify that version 3.0.0 works but 3.0.1 does not. Using also eslint-plugin-prettier@^4.0.0 and prettier@^2.4.1 in my project. eslint has version 7.32.0.