What are dev dependencies?

My understanding is they are used during development, an example being nodemon for hot reloading.

Currently I install these as dev dependencies: lodash and nodemon. Couple questions about that:

  1. What about dotenv? There are a lot of 'somewhere in the middle" libraries like this where I’m not sure if they are more suited to “dev” or regular.

  2. What happens if I install a dependency as dev when it shouldn’t be? I have been tempted to install sequelize and other questionable libraries as dev to see what might happen since I don’t fully understand it. My assumption is that the build step prunes dev dependencies harder in some obscure way.

The difference is whether or not they get used in the code. I would expect lodash to be regular. Dev dependencies are going to be things that are used in dev but not in production, like nodem or testing suites.

Dev dependencies are those things that are only used to build your application, but not to run it. Stuff like babel and webpack are only used to build, so they’re not included at runtime, whereas you’d need lodash for the app to run. If you make a dependency a dev dependency when it should be a normal one, you’ll usually get an error about missing libraries when your app runs.

1 Like

Googling for “npm difference dependency devdependency”:

" dependencies are required to run, devDependencies only to develop, e.g.: unit tests, CoffeeScript to JavaScript transpilation, minification, …"

“The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime.”

" devDependencies contain packages which are used during development or which are used to build your bundle. These packages are neseccery only while you are developing your project. Dependencies contain libs and frameworks your app is built on, such as Vue, React, Angular, Express, JQuery and etc. Your project wont work without these packages(if you are using them, of course)."

" Modules your module needs to run go in dependencies . Modules you need to develop your module go in devDependencies . Or think of it this way: When you deploy your app, modules in dependencies need to be installed or your app won’t work. Modules in devDependencies don’t need to be installed on the production server since you’re not developing on that machine."

  1. You have to decide, if dotenv is necessary for the user to run or only for development. Therefore you have to know, how it works, so read its docs.

  2. The dependency will get installed on a machine, that doesn’t need it, so you’re stealing memory space.