Is React a dev or prod npm dependency?
Gyandeep Singh

Gyandeep Singh @gyandeeps

About: Staff Software Engineer (@Hinge Health) Web, JavaScript, NodeJs, automation, being human, Dad, communication s key 😎 #StriveForGreatness

Location:
Kansas City
Joined:
Jul 2, 2017

Is React a dev or prod npm dependency?

Publish Date: Apr 3 '20
4 4

Do you add react in your dependencies or devDependencies inside package.json and explain why you choose that?

My thoughts

dependencies

It can be here since its part of the application which gets shipped. Or you can say its used by the application/library at runtime.

devDependencies

It is still part of the dependency but its needed during release/compile time but for consumers they don't need it since bundled code already has that in it.

Comments 4 total

  • Sergio Daniel Xalambrí
    Sergio Daniel XalambríApr 4, 2020

    I use dependencies for any package I import in the app code.

    I use devDependencies for any package I don’t import in the app code (test utils, module bundlers, linters, etc.)

    • Gyandeep Singh
      Gyandeep SinghApr 4, 2020

      Well that's the strategy I use too. I was just curious what people thought about it. Technically speaking, if I consume your package via npm I don't need react to be installed since it's already bundled inside your main file.

    • WhiskerFatigue
      WhiskerFatigueApr 8, 2020

      That's a sensible strategy for authoring libraries.

      However for applications the best rule of thumb is: everything you need to build an application is a dependency. So bundlers, linters and tests utils (if linting and tests are part of your build pipleline) are regular dependencies, not devDependencies.

      That way it's always safe to use npm ci in your CI pipeline.

  • Tobias SN
    Tobias SNApr 4, 2020

    It’s a normal dependency. It’s only, and always, used at runtime. The react package is not involved when compiling, I believe @babel/preset-react is responsible for that.

Add comment