dagger/dagger · error

failed to get relative path from context to dep: %w

Error message

failed to get relative path from context to dep: %w

What it means

For a local parent and local dependency, Dagger joins the parent's context directory, source root, and dep path, then computes the lexical relative path from the context directory to the dep. pathutil.LexicalRelativePath failed, so no relative representation exists — typically when the paths are on different drives/volumes or otherwise cannot be related lexically.

Source

Thrown at core/modulesource.go:2182

				})
			}
			if err := dag.Select(ctx, parentSrc.Workspace, &inst, selectors...); err != nil {
				if errors.Is(err, dagql.ErrCacheRecursiveCall) {
					return inst, fmt.Errorf("module %q has a circular dependency on itself through dependency %q", parentSrc.ModuleName, depName)
				}
				return inst, err
			}
			return inst, nil
		}

		switch parentSrc.Kind {
		case ModuleSourceKindLocal:
			// parent=local, dep=local
			// load the dep relative to the parent's source root, from the caller's filesystem
			depPath := filepath.Join(parentSrc.Local.ContextDirectoryPath, parentSrc.SourceRootSubpath, depSrcRef)
			depRelPath, err := pathutil.LexicalRelativePath(parentSrc.Local.ContextDirectoryPath, depPath)
			if err != nil {
				return inst, fmt.Errorf("failed to get relative path from context to dep: %w", err)
			}
			if !filepath.IsLocal(depRelPath) {
				return inst, fmt.Errorf("local module dep source path %q escapes context %q", depRelPath, parentSrc.Local.ContextDirectoryPath)
			}

			selectors := []dagql.Selector{{
				Field: "moduleSource",
				Args: []dagql.NamedInput{
					{Name: "refString", Value: dagql.String(depPath)},
					{Name: "disableFindUp", Value: dagql.Boolean(true)},
				},
			}}
			if depName != "" {
				selectors = append(selectors, dagql.Selector{
					Field: "withName",
					Args: []dagql.NamedInput{
						{Name: "name", Value: dagql.String(depName)},
					},

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Put the dependency module on the same drive/volume as the parent module's context directory (Windows).
  2. Run from within the repository so context and dep share a common root; avoid mixing WSL (\\wsl$) and Windows paths.
  3. Check that the parent's Local.ContextDirectoryPath is a valid absolute path in the expected form.
  4. If using custom directory inputs, ensure the dep path stays under that directory so a relative path exists.
Defensive patterns

Strategy: validation

Validate before calling

depPath := filepath.Join(parentSrc.Local.ContextDirectoryPath, parentSrc.SourceRootSubpath, depRef)
if _, err := pathutil.LexicalRelativePath(parentSrc.Local.ContextDirectoryPath, depPath); err != nil {
    return fmt.Errorf("dep %q cannot be made relative to context (different drive/root?): %v", depRef, err)
}

Prevention

When it happens

Trigger: ResolveDepToSource with parent local and dep local where LexicalRelativePath(contextDirectoryPath, depPath) errors — most commonly Windows paths on different drive letters (C:\ctx vs D:\dep) or malformed absolute paths mixed into the join.

Common situations: Windows users placing the dependency on another drive; context directory paths produced from different mount points (WSL vs Windows paths); corrupted context paths from custom Directory inputs.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/d6ed4930e33b708f. Report an issue: GitHub.