yarnpkg/yarn · error · MessageError

linkMissing

Error message

linkMissing

What it means

`yarn link <name>` consumes a link previously registered in the global link folder (config.linkFolder). The code builds `src = path.join(config.linkFolder, name)` at link.js:45 and only symlinks when `fs.exists(src)` is true; otherwise it throws linkMissing. So the named package was never `yarn link`-registered in its own directory.

Source

Thrown at src/cli/commands/link.js:48

export function setFlags(commander: Object) {
  commander.description('Symlink a package folder during development.');
}

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
  if (args.length) {
    for (const name of args) {
      const src = path.join(config.linkFolder, name);

      if (await fs.exists(src)) {
        const folder = await getRegistryFolder(config, name);
        const dest = path.join(folder, name);

        await fs.unlink(dest);
        await fs.mkdirp(path.dirname(dest));
        await fs.symlink(src, dest);
        reporter.success(reporter.lang('linkUsing', name));
      } else {
        throw new MessageError(reporter.lang('linkMissing', name));
      }
    }
  } else {
    // add cwd module to the global registry
    const manifest = await config.readRootManifest();
    const name = manifest.name;
    if (!name) {
      throw new MessageError(reporter.lang('unknownPackageName'));
    }

    const linkLoc = path.join(config.linkFolder, name);
    if (await fs.exists(linkLoc)) {
      reporter.warn(reporter.lang('linkCollision', name));
    } else {
      await fs.mkdirp(path.dirname(linkLoc));
      await fs.symlink(config.cwd, linkLoc);

      // If there is a `bin` defined in the package.json,

View on GitHub (pinned to c2dda503f3)

Solutions

  1. In the package you want to consume, `cd` into its directory and run `yarn link` (registers it in config.linkFolder).
  2. Then run `yarn link <name>` in the consumer, using the exact `name` from the producer's package.json.
  3. Verify the link folder: `ls $(yarn global dir)/node_modules` to see registered link names.
  4. Check for typos / scope prefix mismatch against the producer package.json `name` field.

Example fix

# before (in consumer)
$ yarn link mylib  # throws linkMissing
# after
$ cd ~/code/mylib && yarn link   # producer side
$ cd ~/code/consumer && yarn link mylib
Defensive patterns

Strategy: validation

Validate before calling

const path = require('path');
const fsp = require('fs').promises;
async function assertLinkable(config, name) {
  const src = path.join(config.linkFolder, name);
  try {
    await fsp.access(src);
    return true;
  } catch {
    throw new Error(`No link registered for '${name}'. Run 'yarn link' in its package dir first.`);
  }
}

Try / catch

try {
  await runYarn(['link', name]);
} catch (e) {
  if (/linkMissing/.test(e.message)) {
    console.error(`'${name}' is not registered. Create it first with 'yarn link' in its source dir.`);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `yarn link foo` when `foo` was never made linkable (no prior `yarn link` run inside foo's dir), or when the registered name differs (typo, scoped-name casing).

Common situations: Forgetting the producer-side `yarn link` step; cross-machine where links live per-user; scoped package registered as `@scope/name` but consumed as `name`.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/e04a2bca4c2ac1f8. Report an issue: GitHub.