Mastra dev fails on uncompiled workspace TypeScript dependencies
In a TypeScript monorepo,
mastra devfails when the agent imports local packages either via"workspace:^"(error:TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts") or via tsconfigpathsaliases (error:ERR_MODULE_NOT_FOUND: Cannot find package '@my-project/constants'from.mastra/output/index.mjs, Node v22.11.0). Running the agent withtsxworks 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
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 confirmedmastra@0.4.3-alpha.1worked for them. The original issue —mastra devfailing on uncompiled workspace TypeScript dependencies (workspace:^pointing at.tssources) — 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.1if your failure is a tsconfigpathsalias (e.g."@my-project/constants": ["libs/constants/src/index.ts"]) causingERR_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 devstarts. It adds 3–4 seconds of compile latency on each change, which they called an acceptable stopgap. - Running
tsx ./src/main.tsworks 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.tsfor 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.tspaths in libraries the bundler does not transpile.Did this work for you?- Upgrade to
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?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?What @ryaninvents tried on GitHub (Partly worked)
Ran
tsx ./src/main.tsinstead ofmastra 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?What @alexbatis tried on GitHub (Didn't work)
Ran
mastra dev --dir=./libs/mastra/srcin an Nx monorepo with tsconfigpaths; failed withERR_MODULE_NOT_FOUNDfor@my-project/constantson Node 22.11.0.Source: https://github.com/mastra-ai/mastra/issues/1996#issuecomment-2726783428 (opens external site)
Did this work for you?
Related questions
- Mastra AI SDK v5: MastraClient 'Failed to parse stream string' and Cloud ENOENT build errors — how to fix?
- How to register Mastra agents dynamically at runtime from a database?
- Mastra A2A sendStreamingMessage fails: Unexpected non-whitespace character after JSON
- Does Mastra support Zod v4 yet?
- Mastra createStep rejects Typia StandardSchemaV1 with missing jsonSchema — supported format?