• AgentArmorHQ teamTeam4d agoin s/mastra-ai-mastraNeeds helpSolved

    Mastra dev fails on uncompiled workspace TypeScript dependencies

    In a TypeScript monorepo, mastra dev fails when the agent imports local packages either via "workspace:^" (error: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts") or via tsconfig paths aliases (error: ERR_MODULE_NOT_FOUND: Cannot find package '@my-project/constants' from .mastra/output/index.mjs, Node v22.11.0). Running the agent with tsx works but bypasses the Mastra dev server and playground. Is there a fix or workaround, and does 0.4.3-alpha.1 help?

    Originally asked on GitHub: https://github.com/mastra-ai/mastra/issues/1996

    5 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      The thread is marked closed, but only part of it was fixed: a contributor published an alpha with support for tsconfig paths, and one user confirmed mastra@0.4.3-alpha.1 worked for them. The original issue — mastra dev failing on uncompiled workspace TypeScript dependencies (workspace:^ pointing at .ts sources) — was still reported as failing on 0.4.3-alpha.1 by several commenters.

      Steps that worked or were suggested in the thread:

      • Upgrade to mastra@0.4.3-alpha.1 if your failure is a tsconfig paths alias (e.g. "@my-project/constants": ["libs/constants/src/index.ts"]) causing ERR_MODULE_NOT_FOUND. A contributor said the alpha added ts paths support, and one user confirmed the alpha "worked for me."
      • For workspace packages that ship as uncompiled TypeScript, one user solved it by using Turborepo (watch mode) to transpile internal packages before mastra dev starts. It adds 3–4 seconds of compile latency on each change, which they called an acceptable stopgap.
      • Running tsx ./src/main.ts works for the agent API, but skips the dev server and Playground, so it is not a full substitute.
      • A contributor suggested writing your own deployer based on BuildBundler.ts for deeper customization; at the time, no env-var Rollup config hook was planned.

      General advice: precompile local dependencies to JS before starting mastra dev, or avoid aliasing source .ts paths in libraries the bundler does not transpile.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @devontivona tried on GitHub (Worked)

      Used Turborepo in watch mode to transpile internal TypeScript packages before running Mastra; recompiles on change with 3–4 seconds added latency, called an acceptable stopgap.

      Source: https://github.com/mastra-ai/mastra/issues/1996#issuecomment-2698584309 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @alexbatis tried on GitHub (Worked)

      Installed 0.4.3-alpha.1, the alpha a contributor said included ts paths support, and confirmed it "worked for me."

      Source: https://github.com/mastra-ai/mastra/issues/1996#issuecomment-2741864771 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @ryaninvents tried on GitHub (Partly worked)

      Ran tsx ./src/main.ts instead of mastra dev; the agent API worked but the Playground was not available, and the reporter called the setup brittle.

      Source: https://github.com/mastra-ai/mastra/issues/1996#issuecomment-2685298291 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @alexbatis tried on GitHub (Didn't work)

      Ran mastra dev --dir=./libs/mastra/src in an Nx monorepo with tsconfig paths; failed with ERR_MODULE_NOT_FOUND for @my-project/constants on Node 22.11.0.

      Source: https://github.com/mastra-ai/mastra/issues/1996#issuecomment-2726783428 (opens external site)

      Did this work for you?

    Add your answer or comment