yarnpkg/yarn · error · MessageError
Package $1 refers to a non-existing file '$0'.
Error message
Package $1 refers to a non-existing file '$0'.
What it means
The file resolver checks fs.exists(loc) before reading a file: dependency; if the path does not exist on disk, it throws. The loc is derived from the dependency pattern; the package name is extracted for the error message.
Source
Thrown at src/resolvers/exotics/file-resolver.js:52
let loc = this.loc;
if (!path.isAbsolute(loc)) {
loc = path.resolve(this.config.lockfileFolder, loc);
}
if (this.config.linkFileDependencies) {
const registry: RegistryNames = 'npm';
const manifest: Manifest = {_uid: '', name: '', version: '0.0.0', _registry: registry};
manifest._remote = {
type: 'link',
registry,
hash: null,
reference: loc,
};
manifest._uid = manifest.version;
return manifest;
}
if (!await fs.exists(loc)) {
throw new MessageError(this.reporter.lang('doesntExist', loc, this.pattern.split('@')[0]));
}
const manifest: Manifest = await (async () => {
try {
return await this.config.readManifest(loc, this.registry);
} catch (e) {
if (e.code === 'ENOENT') {
return {
// This is just the default, it can be overridden with key of dependencies
name: path.dirname(loc),
version: '0.0.0',
_uid: '0.0.0',
_registry: 'npm',
};
}
throw e;
}View on GitHub (pinned to c2dda503f3)
Solutions
- Verify the file: path exists relative to the package.json location
- Use correct relative paths (note resolution is relative to the package, not the repo root)
- Ensure any build step that produces the referenced path has run before install
- Switch to a workspace: protocol for monorepo internal packages
Example fix
// before (package.json) "local-pkg": "file:./built/local-pkg" // after "local-pkg": "file:./packages/local-pkg"
Defensive patterns
Strategy: validation
Validate before calling
import * as fs from './util/fs.js';
import * as path from 'path';
const resolvedLoc = path.resolve(config.cwd, loc);
if (!await fs.exists(resolvedLoc)) {
throw new Error(`file: dependency path does not exist: ${resolvedLoc}`);
} Type guard
async function fileDependencyExists(loc: string): Promise<boolean> {
try { await fs.access(loc); return true; } catch { return false; }
} Try / catch
try {
const manifest = await fileResolver.resolve();
} catch (e) {
if (e.message.includes('non-existing file')) {
// correct the path or build the missing artifact
}
} Prevention
- Verify file: paths exist before committing package.json
- Run build steps that produce file: artifacts before install
- Prefer the workspace: protocol for monorepo-internal packages
When it happens
Trigger: A package.json dependency uses file:./some-path but that path does not exist relative to the project. Checked after the symlink/shortcut path is ruled out.
Common situations: Project moved or renamed, breaking relative file: paths; monorepo workspace paths pointing at non-existent siblings; build artifacts referenced by file: not yet generated.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/9acd7befee708895.
Report an issue: GitHub.