My leader: Thang, Let's config eslint for our app.
Me: Ok, I will do it immediately.
Then as my leader said I went to config eslint for our project. While doing this work, I encountered an interesting problem that I would like to share with you.
Problem
My project is a react app, and we need to have eslint-plugin-react
in order to lint React
code. There are two things that I thought It was interesting.
I did not install
eslint
yet. I only installeslint-plugin-react
. But in mynode_modules
It hadeslint
.My colleagues they also installed as the way I did. But in their
node_modules
, they didn't haveeslint
at all.
Why is it? I didn't know what happened. 🥲
Figure it out
In the first time, I was confused and did some stupid works without thinking 😂.
Some methods I did:
Remove
node_modules
,package-lock.json
of other member.Test this problem in PC of all members 😌.
Try to restart their PC,
What are you thinking? Thang.
Hmm, No method above work. At that point, I understood the resolving problem without thinking is so dangerous. I wasted a lot of time and didn't achieve my goal.
Thang, Keep calm. Let's think about problem!
Why is eslint installed in your PC?
Does eslint-plugin-react has some configs for that?
Should you take a glance at eslint-plugin-react module?
I asked myself in order to find a way to help me resolve this problem.
When I took a glance at package.json
of eslint-plugin-react
, I saw it has the config:
"peerDependencies": {
"eslint": "^3 || ^4 || ^5 || ^6 || ^7"
}
Oh, It has eslint
, wait a second what's peerDependencies
. Hmm, it's a setting, in order to compatibility eslint-plugin-react
with eslint
which is declared in peerDependencies. So when I install eslint-plugin-react
, eslint
is hosted as well.
Ok, I understood a little bit. But Why does only my PC has eslint?
. Read a little bit npm Docs
and saw this.
Maybe the problem is npm
version.
Immediately, I checked npm
version of all members. Wow! Their npm
version is less than 7
and it makes peerDependencies
go away. Then I tried to update their version to v7
and of course, everything works properly.
Top comments (0)