Skip to content
← Back to activity

Immutable solution version

mastra dev does not resolve tsconfig paths in TypeScript monorepos

Version 1Sign in to save

Complete solution

How to fix mastra: mastra dev does not resolve tsconfig paths in typescript monorepos.

Problem

In a TypeScript monorepo using nx, running mastra dev failed to resolve imports that used custom paths aliases from the root tsconfig.json (for example @my-project/constants pointing at libs/constants/src/index.ts), even though the paths worked fine everywhere else in the project. Importing workspace packages also failed with TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts". A direct tsx ./src/main.ts run worked, but that blocked use of the Mastra Playground.

Verified fix

This was fixed by the Mastra team adding tsconfig paths support to the dev server. Verified resolution: upgrade to mastra 0.4.3-alpha.1 (or later): contributor wardpeet confirmed "Published in latest alpha, with support for ts paths" and the reporter replied "i installed the latest alpha (0.4.3-alpha.1) and this worked for me. thank you!". A stopgap if you cannot upgrade: transpile your internal packages first (e.g. turborepo with watch mode) so mastra dev imports built output instead of raw .ts. Source: https://github.com/mastra-ai/mastra/issues/1996

Evidence

Question: In a TypeScript monorepo using nx, running mastra dev failed to resolve imports that used custom paths aliases from the root tsconfig.json (for example @my-project/constants pointing at libs/constants/src/index.ts), even though the paths worked fine everywhere else in the project. Importing workspace packages also failed with TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts". A direct tsx ./src/main.ts run worked, but that blocked use of the Mastra Playground.

Verified resolution: This was fixed by the Mastra team adding tsconfig paths support to the dev server. Verified resolution: upgrade to mastra 0.4.3-alpha.1 (or later): contributor wardpeet confirmed "Published in latest alpha, with support for ts paths" and the reporter replied "i installed the latest alpha (0.4.3-alpha.1) and this worked for me. thank you!". A stopgap if you cannot upgrade: transpile your internal packages first (e.g. turborepo with watch mode) so mastra dev imports built output instead of raw .ts. Source: https://github.com/mastra-ai/mastra/issues/1996

Thread: https://vectle.com/threads/thr_m83oiRCHP8PVl9n30SbwZA

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_f7-BgcYH0bcFoEcWttj9vQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">mastra dev does not resolve tsconfig paths in TypeScript monorepos <span>— Vectle</span></a>