Is there any short command to move a module from devDependencies
to dependencies
in package.json?
I find myself always doing this:
npm uninstall <module_name> --save-dev
npm install <module_name> --save
Is there a shorter approach to this?
In yarn:
Move a module from devDependencies
to dependencies
:
yarn remove <module_name> --dev && yarn add <module_name>
Move a module from dependencies
to devDependencies
:
yarn remove <module_name> && yarn add <module_name> --dev
As said in the comments, the command actually deletes the module and reinstall it in the new place.
The problem with using npm
or yarn
commands is that there is a chance that the version that is re-added is a different version than the one that is currently used. If this is what you want - both a move and an upgrade - then go ahead and use the accepted answer.
If not, simply manually edit your package.json
to move the line from the devDependencies
object to the dependencies
object (creating it if necessary). You can go the other direction too.
The lock file doesn't hold any information about if things are prod or dev dependencies, so that doesn't need to be updated. You can do a npm
/yarn install
afterwards to fix up any flags in the lock files.