Skip to content
Nx Cloud CI is in private beta 10.6× faster average CI time with 79% less compute. Join the beta

▸ addDependenciesToPackageJson(tree, dependencies, devDependencies, packageJsonPath?, keepExistingVersions?): GeneratorCallback

Add Dependencies and Dev Dependencies to package.json

For example:

addDependenciesToPackageJson(tree, { react: 'latest' }, { jest: 'latest' })

This will add react and jest to the dependencies and devDependencies sections of package.json respectively.

NameTypeDescription
treeTreeTree representing file system to modify
dependenciesRecord<string, string>Dependencies to be added to the dependencies section of package.json
devDependenciesRecord<string, string>Dependencies to be added to the devDependencies section of package.json
packageJsonPath?stringPath to package.json
keepExistingVersions?booleanIf true, prevents existing dependencies from being bumped to newer versions

GeneratorCallback

Callback to install dependencies only if necessary, no-op otherwise