{"record":{"id":"28e6a7a18d978837","repo":"yarnpkg/yarn","slug":"importresolvefailed","errorCode":null,"errorMessage":"importResolveFailed","messagePattern":"importResolveFailed","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/import.js","lineNumber":186,"sourceCode":"      : await this.request.findVersionOnRegistry(fixedVersionPattern);\n    return manifest;\n  }\n\n  async _resolveFromFixedVersions(): Promise<Manifest> {\n    invariant(this.request instanceof ImportPackageRequest, 'request must be ImportPackageRequest');\n    const {name} = normalizePattern(this.pattern);\n    invariant(\n      this.request.dependencyTree instanceof LogicalDependencyTree,\n      'dependencyTree on request must be LogicalDependencyTree',\n    );\n    const fixedVersionPattern = this.request.dependencyTree.getFixedVersionPattern(name, this.request.parentNames);\n    const info = await this.config.getCache(`import-resolver-${fixedVersionPattern}`, () =>\n      this.resolveFixedVersion(fixedVersionPattern),\n    );\n    if (info) {\n      return info;\n    }\n    throw new MessageError(this.reporter.lang('importResolveFailed', name, this.getCwd()));\n  }\n\n  async _resolveFromNodeModules(): Promise<Manifest> {\n    const {name} = normalizePattern(this.pattern);\n    let cwd = this.getCwd();\n    while (!path.relative(this.config.cwd, cwd).startsWith('..')) {\n      const loc = path.join(cwd, 'node_modules', name);\n      const info = await this.config.getCache(`import-resolver-${loc}`, () => this.resolveLocation(loc));\n      if (info) {\n        return info;\n      }\n      cwd = path.resolve(cwd, '../..');\n    }\n    throw new MessageError(this.reporter.lang('importResolveFailed', name, this.getCwd()));\n  }\n\n  resolve(): Promise<Manifest> {\n    if (this.request instanceof ImportPackageRequest && this.request.dependencyTree) {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/import.js#L168-L204","documentation":"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'.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Ensure network access (or pre-populate the yarn cache) so each pinned package is resolvable.","Regenerate `package-lock.json` with `npm install` on a clean tree before importing.","Resolve private/git deps in package.json to reachable URLs.","Fall back to importing from `node_modules` (delete/corrupt package-lock to trigger the node_modules path)."],"exampleFix":"// before\n$ yarn import\n→ Import of lodash failed starting in /repo\n\n// after\n$ npm install        # regenerate a consistent package-lock.json\n$ yarn import","handlingStrategy":"fallback","validationCode":"// Verify each lockfile entry is resolvable before importing\nasync function allLockfileEntriesResolvable(lock: { dependencies: Record<string, any> }, resolve): Promise<string[]> {\n  const bad: string[] = [];\n  for (const [name, node] of Object.entries(lock.dependencies || {})) {\n    if (!await resolve(`${name}@${node.version}`)) bad.push(name);\n  }\n  return bad;\n}","typeGuard":"function lockfileEntryResolvable(node: { version?: string } | undefined): boolean {\n  return Boolean(node && typeof node.version === 'string' && node.version.length > 0);\n}","tryCatchPattern":"try {\n  await yarnImport();\n} catch (e) {\n  if (/Import of .* failed starting in/.test(e.message)) {\n    // fall back: delete package-lock.json, import from node_modules instead\n    await fs.unlink('package-lock.json');\n    await yarnImport();\n  } else throw e;\n}","preventionTips":["Run `npm install` on a clean tree first so package-lock.json is internally consistent.","Ensure registry reachability (or a warm cache) before importing.","Resolve git/file deps to concrete URLs in package.json."],"tags":["yarn-import","resolution","package-lock","registry"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}