DEV Community

Gyandeep Singh
Gyandeep Singh

Posted on

Is React a dev or prod npm dependency?

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.

Top comments (4)

Collapse
 
sergiodxa profile image
Sergio Daniel Xalambrí

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.)

Collapse
 
whiskerfatigue profile image
WhiskerFatigue

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.

Collapse
 
gyandeeps profile image
Gyandeep Singh

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.

Collapse
 
tobiassn profile image
Tobias SN • Edited

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.