jdx/mise · error

Go workspace module {} is missing go.mod

Error message

Go workspace module {} is missing go.mod

What it means

Go workspace (go.work) discovery resolves each module candidate listed by the Go workspace. If the candidate go.mod path does not exist, mise first checks whether it resolves outside the canonical workspace root (in which case it is silently skipped); if it still falls inside the root but is missing, discovery bails saying the module is missing its go.mod.

Source

Thrown at src/task/workspace/go.rs:63

        for directory in module_directories {
            let candidate = if directory.is_absolute() {
                directory
            } else {
                workspace_root.join(directory)
            };
            let lexical_candidate = lexical_absolute(&candidate)?;
            if !lexical_candidate.starts_with(&lexical_root)
                && !lexical_candidate.starts_with(&canonical_root)
            {
                continue;
            }
            let candidate = lexical_candidate;
            if !context.exists(&candidate) {
                if missing_path_resolves_outside(&candidate, &lexical_root, &canonical_root)? {
                    continue;
                }
                bail!(
                    "Go workspace module {} is missing {GO_MOD}",
                    candidate.display()
                );
            }
            let canonical_module = context.canonicalize(&candidate).wrap_err_with(|| {
                format!(
                    "failed to resolve Go workspace module {}",
                    candidate.display()
                )
            })?;
            let Ok(relative) = canonical_module.strip_prefix(&canonical_root) else {
                continue;
            };
            if !context.is_file(&canonical_module.join(GO_MOD)) {
                bail!(
                    "Go workspace module {} is missing {GO_MOD}",
                    candidate.display()
                );

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Run `go mod init <module-path>` in the referenced directory (or `go work use -r .`) so the go.mod exists.
  2. Remove the stale `use` entry from go.work with `go work use` / `go work edit -dropuse ./path`.
  3. Fix the path in go.work if it has a typo; ensure all listed modules are present at that branch/checkout.

Example fix

// before (go.work)
go 1.22
use (
	./apps/api
	./apps/missing // directory has no go.mod
)

// after
go 1.22
use ./apps/api
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const work = fs.readFileSync('go.work', 'utf8');
for (const m of work.matchAll(/use\s+(\.\/[^\s)]+)/g)) {
  if (!fs.existsSync(`${m[1]}/go.mod`)) {
    throw new Error(`go.work uses ${m[1]} but go.mod is missing; run 'go mod init' or drop the use line`);
  }
}

Try / catch

try {
  await mise.run(['task', 'run', name]);
} catch (e) {
  if (/Go workspace module .* is missing go\.mod/.test(e.message)) {
    const dir = e.message.match(/module (\S+) is missing/)?.[1];
    require('child_process').execSync(`go mod init $(basename ${dir})`, { cwd: dir });
  } else { throw e; }
}

Prevention

When it happens

Trigger: A go.work `use` entry (or member directory found during discovery) points at a directory that exists in the workspace but has no go.mod file; discover_with_context, called from discover, hits context.exists(candidate) == false and missing_path_resolves_outside returns false.

Common situations: Deleting a module's go.mod while leaving its `use` line in go.work; adding a `use ./pkg` before running `go mod init`; switching branches where go.work references modules the branch doesn't contain; typos in the use path creating a nonexistent in-root directory.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/72a68706d051958f. Report an issue: GitHub.