{"record":{"id":"75a2338cb06b997c","repo":"mastra-ai/mastra","slug":"invalid-tsconfig","errorCode":"INVALID_TSCONFIG","errorMessage":"INVALID_TSCONFIG","messagePattern":"INVALID_TSCONFIG","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/lint/rules/tsConfigRule.ts","lineNumber":40,"sourceCode":"    if (!tsConfig) {\n      return [\n        {\n          code: 'MISSING_TSCONFIG',\n          severity: 'warning',\n          scope: 'project',\n          message: 'No tsconfig.json found. Mastra projects should include a TypeScript config.',\n          fix: 'Add a tsconfig.json file. See https://mastra.ai/en/docs/getting-started/installation#initialize-typescript',\n        },\n      ];\n    }\n\n    const { module, moduleResolution } = tsConfig.compilerOptions || {};\n\n    const isValidConfig = moduleResolution === 'bundler' || module === 'CommonJS';\n    if (!isValidConfig) {\n      return [\n        {\n          code: 'INVALID_TSCONFIG',\n          severity: 'error',\n          scope: 'project',\n          message:\n            'tsconfig.json must set either compilerOptions.moduleResolution to \"bundler\" or compilerOptions.module to \"CommonJS\".',\n          fix: 'Update tsconfig.json with either { \"compilerOptions\": { \"moduleResolution\": \"bundler\" } } or { \"compilerOptions\": { \"module\": \"CommonJS\" } }. See https://mastra.ai/en/docs/getting-started/installation#initialize-typescript',\n        },\n      ];\n    }\n\n    return [];\n  },\n};\n","sourceCodeStart":22,"sourceCodeEnd":53,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/lint/rules/tsConfigRule.ts#L22-L53","documentation":"The lint rule checks that tsconfig.json compilerOptions use either moduleResolution \"bundler\" or module \"CommonJS\", which are the configurations Mastra supports for building/loading user code. Any other combination (e.g. ESM-style module without bundler resolution) throws this project-scope error.","triggerScenarios":"`mastra lint` finds a tsconfig.json whose compilerOptions.module/moduleResolution are missing or set to unsupported values (e.g. module: ESNext with moduleResolution: node).","commonSituations":"Projects scaffolded for ESM with `moduleResolution: node16`/`nodenext`; tsconfig created by `tsc --init` defaults; migrating a Mastra project from an older template.","solutions":["Set compilerOptions.moduleResolution to \"bundler\" in tsconfig.json","Alternatively set compilerOptions.module to \"CommonJS\"","Run `mastra init` to regenerate a known-good tsconfig"],"exampleFix":"// before\n{ \"compilerOptions\": { \"module\": \"ESNext\", \"moduleResolution\": \"node\" } }\n// after\n{ \"compilerOptions\": { \"module\": \"ESNext\", \"moduleResolution\": \"bundler\" } }","handlingStrategy":"validation","validationCode":"const tsconfig = JSON.parse(readFileSync(join(rootDir, 'tsconfig.json'), 'utf-8'));\nconst { module, moduleResolution } = tsconfig.compilerOptions ?? {};\nif (moduleResolution !== 'bundler' && module !== 'CommonJS') {\n  throw new Error('Set compilerOptions.moduleResolution=\"bundler\" or module=\"CommonJS\"');\n}","typeGuard":"const isMastraCompatible = (c: unknown): c is { compilerOptions?: { module?: string; moduleResolution?: string } } =>\n  typeof c === 'object' && c !== null;\nconst isValid = (c: { compilerOptions?: { module?: string; moduleResolution?: string } }) =>\n  c.compilerOptions?.moduleResolution === 'bundler' || c.compilerOptions?.module === 'CommonJS';","tryCatchPattern":"try {\n  await mastraLint();\n} catch (e) {\n  if ((e as Error).message.includes('INVALID_TSCONFIG')) {\n    console.error('Fix tsconfig compilerOptions: moduleResolution=bundler or module=CommonJS');\n  } else throw e;\n}","preventionTips":["Use Mastra's official tsconfig template from `mastra init`","Keep moduleResolution: \"bundler\" in ESM projects","Re-check tsconfig after upgrading TypeScript or templates","Add a lint/CI check validating compilerOptions"],"tags":["typescript","config","lint","module-resolution"],"backgroundTag":"invalid-tsconfig","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}