Package Managers

The package manager aspect directs and operates package managers like Yarn, pnpm, or any other supported CommonJS package manager using the bit install command.

For package managers to work properly, Bit uses Workspace features such as Yarn workspaces or npm workspaces that allow the installation of independent components with conflicting dependencies on the same workspace.

Package Managers such as Yarn, pnpm and NPM In Bit are responsible for node_modules installation. Bit works with any of them, making sure to interact with their latest APIs, deduping component dependencies properly prior to node_modules installation.

Deduping of dependencies

Bit handles deduping of component dependencies in the workspace. This means every component can be resolved with a different version of a specific package in case of conflicts in Component versions between different Workspace Components.

├── base-ui
    ├── ui
        ├── button
          ├── node_modules -> created in case of conflicts in Component versions between different Workspace Components
          ├── index.ts
          ├── button.ts
          ├── button.spec.ts
          ├── button.docs.md
          ├── ...
    ├── hooks
        ├── use-product
          ├── index.ts
          ├── use-product.ts
          ├── button.spec.ts
          ├── button.docs.md
          ├── ...
├── ecommerce
    ├── ui
        ├── button
          ├── node_modules -> created in case of conflicts in Component versions between different Workspace Components.
          ├── index.ts
          ├── button.ts
          ├── button.spec.ts
          ├── button.docs.md
          ├── ...
├── ...
CopiedCopy

pnpm

pnpm is the default package manager for Bit.

The pnpm aspect uses Bit's deduping algorithm to ensure only required symlinks are written to the Workspace file system. It searches for a common version that satisfies most components using the same dependency (taking into consideration permitted version ranges configured for each component) and installs it at the workspace root directory, where it can be shared by multiple dependent components. Versions that are used by a minority of components will be installed nested in each component directory.

Yarn

Bit supports Yarn 2.0, and uses Yarn Workspaces to make sure proper deduping between components.

Using package managers directly

Other package managers like NPM, Yarn and pnpm can also be used directly. To use them configure a postinstall in your project's package.json file to make sure Workspace Component Links are generated properly and new Component versions are imported.

note

We recommend to use bit install for the installation and management of modules in the node_modules directory.

{
  "name": "my workspace",
  "scripts": {
    "post-install": "bit import && bit link"
  }
}
CopiedCopy