yarnpkg/yarn · error · MessageError

importResolveFailed

Error message

importResolveFailed

What it means

When `yarn import` reads from `package-lock.json`, `_resolveFromFixedVersions` looks up the package's fixed version in the logical dependency tree, then tries to resolve it (via `getCache`). If resolution returns nothing (`if (info)` is false), `import.js:186` throws `importResolveFailed` with the package name and cwd. The lang string: 'Import of $0 failed starting in $1'.

Source

Thrown at src/cli/commands/import.js:186

      : await this.request.findVersionOnRegistry(fixedVersionPattern);
    return manifest;
  }

  async _resolveFromFixedVersions(): Promise<Manifest> {
    invariant(this.request instanceof ImportPackageRequest, 'request must be ImportPackageRequest');
    const {name} = normalizePattern(this.pattern);
    invariant(
      this.request.dependencyTree instanceof LogicalDependencyTree,
      'dependencyTree on request must be LogicalDependencyTree',
    );
    const fixedVersionPattern = this.request.dependencyTree.getFixedVersionPattern(name, this.request.parentNames);
    const info = await this.config.getCache(`import-resolver-${fixedVersionPattern}`, () =>
      this.resolveFixedVersion(fixedVersionPattern),
    );
    if (info) {
      return info;
    }
    throw new MessageError(this.reporter.lang('importResolveFailed', name, this.getCwd()));
  }

  async _resolveFromNodeModules(): Promise<Manifest> {
    const {name} = normalizePattern(this.pattern);
    let cwd = this.getCwd();
    while (!path.relative(this.config.cwd, cwd).startsWith('..')) {
      const loc = path.join(cwd, 'node_modules', name);
      const info = await this.config.getCache(`import-resolver-${loc}`, () => this.resolveLocation(loc));
      if (info) {
        return info;
      }
      cwd = path.resolve(cwd, '../..');
    }
    throw new MessageError(this.reporter.lang('importResolveFailed', name, this.getCwd()));
  }

  resolve(): Promise<Manifest> {
    if (this.request instanceof ImportPackageRequest && this.request.dependencyTree) {

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Ensure network access (or pre-populate the yarn cache) so each pinned package is resolvable.
  2. Regenerate `package-lock.json` with `npm install` on a clean tree before importing.
  3. Resolve private/git deps in package.json to reachable URLs.
  4. Fall back to importing from `node_modules` (delete/corrupt package-lock to trigger the node_modules path).

Example fix

// before
$ yarn import
→ Import of lodash failed starting in /repo

// after
$ npm install        # regenerate a consistent package-lock.json
$ yarn import
Defensive patterns

Strategy: fallback

Validate before calling

// Verify each lockfile entry is resolvable before importing
async function allLockfileEntriesResolvable(lock: { dependencies: Record<string, any> }, resolve): Promise<string[]> {
  const bad: string[] = [];
  for (const [name, node] of Object.entries(lock.dependencies || {})) {
    if (!await resolve(`${name}@${node.version}`)) bad.push(name);
  }
  return bad;
}

Type guard

function lockfileEntryResolvable(node: { version?: string } | undefined): boolean {
  return Boolean(node && typeof node.version === 'string' && node.version.length > 0);
}

Try / catch

try {
  await yarnImport();
} catch (e) {
  if (/Import of .* failed starting in/.test(e.message)) {
    // fall back: delete package-lock.json, import from node_modules instead
    await fs.unlink('package-lock.json');
    await yarnImport();
  } else throw e;
}

Prevention

When it happens

Trigger: `LogicalDependencyTree.getFixedVersionPattern(name, parentNames)` returns a pattern, but `this.resolveFixedVersion(pattern)` yields no resolvable info — the package/version pinned in the lockfile cannot be fetched from the registry or cache.

Common situations: Offline import without the packages cached, package-lock referencing a private/git/file dependency the importer cannot reach, or a lockfile with a version that no longer exists on the registry.

Related errors


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