add Verified current stable Not installed? Package Management

Add / Install Module Save Dependency

Install Module Save Dependency

Adds a specified module as a dependency to the project with Yarn.

$
Terminal
yarn add <module_name>@<version>

When To Use

When a specific module is required for the application functionality during runtime.

Pro Tip

Consider adding the --optional flag if the dependency is not critical for the app to run, optimizing installation.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
yarn add <module_name>@<version>

Anatomy of Output

Understanding the result

success Installed 1 package. Installation Status

Confirms that a module has been added.

info New dependency "{{module_name}}": version {{version}} Dependency Update

Indicates the module and its version are now part of dependencies.

info Updated lockfile. Lockfile Status

Yarn.lock file has been updated accordingly.

Troubleshooting

Common pitfalls

Error: Package not found

Solution: Check the package name and internet connection.

Error: Invalid version

Solution: Ensure the version string follows semantic versioning standards.

Error: Permission denied

Solution: Run the command with elevated permissions.

Command Breakdown

What each part is doing

yarn
Base Command
The executable that performs this operation. Here it runs Add before the shell applies any redirect operators.
<module_name>
module name
The value supplied for module name.
<version>
version
The value supplied for version.

Alternative Approaches

Comparable commands in other tools

Alternative package management tools for the same job.