DEV Community

Cover image for Did eslint only love my PC ?
Phan Công Thắng
Phan Công Thắng

Posted on • Edited on • Originally published at thangphan.xyz

Did eslint only love my PC ?

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.

  1. I did not install eslint yet. I only install eslint-plugin-react. But in my node_modules It had eslint.

  2. My colleagues they also installed as the way I did. But in their node_modules, they didn't have eslint at all.

Eslint Plugin React

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:

  1. Remove node_modules, package-lock.json of other member.

  2. Test this problem in PC of all members 😌.

  3. 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"
 }
Enter fullscreen mode Exit fullscreen mode

peerDependency

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.

Version Checking

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)