Using Remote Scopes

This page is for teams looking to self-host a Bit Scope.

Collaborating on Bit components require setting up remote scopes accessible for all collaborators. Remote scopes should also be accessible for one-another, so that they can have dependencies.

Managing a distributed network of scopes requires each node in the network to know which remotes to communicate with. These nodes are called remotes in Bit, and managing them, regardless of whether the node is a developer workstation or a remote scope, is done with the remote command.

Remotes for the workspace

When you set up a remote scope, all developers that need to be able to access the scope should add it as a remote:

bit remote add http://{host}:{host-port}

When a scope is added as a remote, a workspace may export/import components and use the scope.

Network of scopes

If you have components that depend on components from other scopes, you need to inter-connect the scopes.

For example, if a component in scope billing is dependent on a component in scope design-system, you need to make scope billing aware of scope design-system. To do this, first log to the machine hosting billing and run:

bit remote add http://{design-system-host}:{host-port}

The network needs to have remote pointing in the direction of the dependencies. So if design-system is dependent on billing, you need to add billing as a remote to design-system as well.

Automate with a scope resolver

Another option is to define a resolve function that resolves the scopes. The function is defined in the scope.json in the scope, and Bit uses it whenever it needs to resolve paths between scopes.

  "name": "bit.envs",
  "remotes": {},
  "resolverPath": "/app/resolver.js"

The function gets the destination scope name (the destination from to get the dependency) and source scope name (the scope that has the dependent) as parameters. It should return a valid URL of the destination, e.g: file:///tmp/my-scope-name.

The example below is code taken from

// /app/resolver.js
const http = require('http');
module.exports = (dst, src) =>
  new Promise((resolve, reject) =>
      (res) => {
        let rawData = '';
        res.on('data', (chunk) => (rawData += chunk));
        res.on('end', () =>
          res.statusCode === 200
            ? resolve(`file:///tmp/bithub/${JSON.parse(rawData).payload}`)
            : reject({
                code: 134,
                  `unable to export components to ${src} because they have dependencies on components in ${dst}. ` +
                  'bit does not allow setting dependencies between components in private scopes managed by different owners.',
                sourceScope: dst,
                destinationScope: src,