FoundationAgents/MetaGPT · error · ValueError

dist_dir must be an absolute path.

Error message

dist_dir must be an absolute path.

What it means

Engineer2._deploy_to_public requires an absolute dist_dir (the built web project output). If a relative path is given, it attempts to fix it via editor._try_fix_path; when the fixed path still does not exist on disk, this ValueError is raised. It signals the build output directory could not be located.

Solutions

  1. Run the web build (npm run build) first and confirm the dist folder exists on disk
  2. Pass an absolute path to _deploy_to_public / the deploy action
  3. Check editor._try_fix_path's base working directory matches where the build output lives

Example fix

// before
await self._deploy_to_public("dist")  # relative, may not resolve -> ValueError

// after
await self._deploy_to_public(str(project_root / "dist"))  # absolute path
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
dist = Path(dist_dir)
if not dist.is_absolute():
    dist = (project_root / dist).resolve()
if not dist.exists():
    raise FileNotFoundError(f"build output not found at {dist}; run the web build first")

Try / catch

try:
    await self._deploy_to_public(dist_dir)
except ValueError as e:
    if "absolute path" in str(e):
        raise RuntimeError(f"build output missing for {dist_dir}; run npm run build first") from e
    raise

Prevention

When it happens

Trigger: The deploy action receives a relative dist_dir (e.g. "dist" or "build") from the LLM-driven workflow, and the editor's working directory does not contain that folder — either the build never ran or it output elsewhere.

Common situations: The web build step failed or was skipped so dist/ was never created; the agent passed a path relative to a different cwd; project scaffold put build output in a nested folder.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/6d423c1fc6d4b007. Report an issue: GitHub.

Appendix: source

Thrown at metagpt/roles/di/engineer2.py:153

            await reporter.async_report({"type": "code", "filename": Path(path).name, "src_path": path}, "meta")
            rsp = await self.llm.aask(context, system_msgs=[WRITE_CODE_SYSTEM_PROMPT])
            code = CodeParser.parse_code(text=rsp)
            await awrite(path, code)
            await reporter.async_report(path, "path")

        # TODO: Consider adding line no to be ready for editing.
        return f"The file {path} has been successfully created, with content:\n{code}"

    async def _deploy_to_public(self, dist_dir):
        """fix the dist_dir path to absolute path before deploying
        Args:
            dist_dir (str): The dist directory of the web project after run build. This must be an absolute path.
        """
        # Try to fix the path with the editor's working directory.
        if not Path(dist_dir).is_absolute():
            default_dir = self.editor._try_fix_path(dist_dir)
            if not default_dir.exists():
                raise ValueError("dist_dir must be an absolute path.")
            dist_dir = default_dir
        return await self.deployer.deploy_to_public(dist_dir)

    async def _eval_terminal_run(self, cmd):
        """change command pull/push/commit to end."""
        if any([cmd_key_word in cmd for cmd_key_word in ["pull", "push", "commit"]]):
            # The Engineer2 attempts to submit the repository after fixing the bug, thereby reaching the end of the fixing process.
            logger.info("Engineer2 use cmd:{cmd}\nCurrent test case is finished.")
            # Set self.rc.todo to None to stop the engineer.
            self._set_state(-1)
        else:
            command_output = await self.terminal.run_command(cmd)
        return command_output

    async def _end(self):
        if not self.planner.plan.is_plan_finished():
            self.planner.plan.finish_all_tasks()
        return await super()._end()

View on GitHub (pinned to 11cdf466d0)