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.
- npx react-native some
- 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:

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 22 (1 by maintainers)
For those using
yarn
, trynpx 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.:
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 (Node16.6.0
, NPM7.20.6
) and Mac (Node16.7.0
, NPM7.20.3
).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).
Installing as instructed/recommended that moves the error to a missing
prettier
config package.Installing
eslint-config-prettier
in turn mentions an issue withglobals/jest
.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
:The first line (v2.1.2) comes from
@react-native-community/eslint-config
, the second (v2.5.1) from mypackage.json
To make sure that only 1 version is installed:
prettier
requirements (the version in your package.json and the version of all libs using prettier) are compatible.yarn
againfor me, with rn 0.64.2 and @react-native-community/eslint-config@3.0.1 , when yarn install, i got the error:
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 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 but3.0.1
does not. Using alsoeslint-plugin-prettier@^4.0.0
andprettier@^2.4.1
in my project.eslint
has version7.32.0
.