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
- 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).
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
- 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.
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
- importSourceFilesCorrupted
- registryNoVersions
- packageNotFoundRegistry
- Unexpected audit response (Invalid JSON): ${response}
- Unexpected audit response (Missing Metadata): ${JSON.stringi
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/28e6a7a18d978837.
Report an issue: GitHub.