Skip to content

[BUG] tsconfig.json alias not working for extended configs #11770

@LekoArts

Description

@LekoArts

Describe the Bug

When the root tsconfig.json is extended from another tsconfig.json file, the compilerOptions.paths is not working. As in I can't use path aliases in Mastra files.

Steps To Reproduce

  1. Create a new project with pnpm create mastra@beta
  2. Add a new file at .test/tsconfig.json with these contents:
{
	"compilerOptions": {
		"paths": {
			"$lib": [
				"../src/lib"
			],
			"$lib/*": [
				"../src/lib/*"
			],
		},
		"rootDirs": [
			"..",
			"./types"
		],
		"verbatimModuleSyntax": true,
		"isolatedModules": true,
		"lib": [
			"esnext",
			"DOM",
			"DOM.Iterable"
		],
		"moduleResolution": "bundler",
		"module": "esnext",
		"noEmit": true,
		"target": "esnext"
	},
	"include": [
		"ambient.d.ts",
		"non-ambient.d.ts",
		"./types/**/$types.d.ts",
		"../src/**/*.js",
		"../src/**/*.ts",
		"../tests/**/*.js",
		"../tests/**/*.ts",
	],
	"exclude": [
		"../node_modules/**",
	]
}
  1. Edit the root tsconfig.json to this:
{
	"extends": "./.test/tsconfig.json",
	"compilerOptions": {
		"rewriteRelativeImportExtensions": true,
		"moduleResolution": "bundler",
		"resolveJsonModule": true,
		"allowJs": true,
		"checkJs": true,
		"strict": true,
		"sourceMap": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"skipLibCheck": true
	}
}
  1. Create a src/lib/index.ts file with contents: export const TEST = '123'
  2. Change src/mastra/index.ts to this:
import { Mastra } from '@mastra/core/mastra';
import { PinoLogger } from '@mastra/loggers';
import { LibSQLStore } from '@mastra/libsql';
import { Observability } from '@mastra/observability';
import { weatherWorkflow } from './workflows/weather-workflow';
import { weatherAgent } from './agents/weather-agent';
import { TEST } from '$lib';
import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';

export const mastra = new Mastra({
  workflows: { weatherWorkflow },
  agents: { weatherAgent },
  scorers: { toolCallAppropriatenessScorer, completenessScorer, translationScorer },
  storage: new LibSQLStore({
    id: "mastra-storage",
    // stores observability, scores, ... into memory storage, if it needs to persist, change to file:../mastra.db
    url: ":memory:",
  }),
  logger: new PinoLogger({
    name: `Mastra ${TEST}`,
    level: 'info',
  }),
  observability: new Observability({
    // Enables DefaultExporter and CloudExporter for tracing
    default: { enabled: true },
  }),
});
  1. Run mastra dev

Error:

◐ Preparing development environment...
✓ Initial bundle complete
◇ Starting Mastra dev server...
node:internal/modules/package_json_reader:268
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '$lib' imported from /Users/lejoe/code/playground/ts-paths-debug/.mastra/output/index.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
    at packageResolve (node:internal/modules/esm/resolve:768:81)
    at moduleResolve (node:internal/modules/esm/resolve:858:18)
    at defaultResolve (node:internal/modules/esm/resolve:990:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:768:20)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:745:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:318:38)
    at #link (node:internal/modules/esm/module_job:208:49)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Link to Minimal Reproducible Example

Expected Behavior

Path alias works

Environment Information

System:
    OS: macOS 26.2
    CPU: (12) arm64 Apple M4 Pro
    Memory: 2.98 GB / 48.00 GB
    Shell: 5.9 - /opt/local/bin/zsh
  Binaries:
    Node: 24.8.0 - /Users/lejoe/.local/state/fnm_multishells/77709_1767972886475/bin/node
    npm: 11.6.0 - /Users/lejoe/.local/state/fnm_multishells/77709_1767972886475/bin/npm
    pnpm: 10.23.0 - /Users/lejoe/.local/state/fnm_multishells/77709_1767972886475/bin/pnpm
    bun: 1.2.21 - /Users/lejoe/.bun/bin/bun
    Deno: 2.5.0 - /Users/lejoe/.deno/bin/deno
  Browsers:
    Chrome: 143.0.7499.171
    Firefox: 146.0
    Safari: 26.2
  npmPackages:
    @mastra/core: 1.0.0-beta.21 => 1.0.0-beta.21 
    @mastra/evals: 1.0.0-beta.4 => 1.0.0-beta.4 
    @mastra/libsql: 1.0.0-beta.11 => 1.0.0-beta.11 
    @mastra/loggers: 1.0.0-beta.4 => 1.0.0-beta.4 
    @mastra/memory: 1.0.0-beta.12 => 1.0.0-beta.12 
    @mastra/observability: 1.0.0-beta.10 => 1.0.0-beta.10 
    @types/node: ^25.0.3 => 25.0.3 
    mastra: 1.0.0-beta.13 => 1.0.0-beta.13 
    typescript: ^5.9.3 => 5.9.3 
    zod: ^4.3.5 => 4.3.5 
  npmGlobalPackages:
    corepack: 0.34.0
    netlify-cli: 23.9.5
    npm: 11.6.0
    secco: 3.1.2

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions