M
Mastra•2w ago
kosukeoya

Could you include the src files in packages like @mastra/core?

When implementing applications using mastra, we've encountered issues that aren't actually with our application but with the core mastra library itself. On several occasions, we've spent significant time debugging issues in mastra itself. I believe including source files and properly distributing sourcemaps would make debugging much easier. While this would increase the npm install time. What are your thoughts on this?
9 Replies
kosukeoya
kosukeoyaOP•2w ago
Currently, we're writing .pnpmfile.cjs files like this and referencing locally cloned mastra for debugging purposes.
const mastraRepoRoot = process.env.MASTRA_REPO_ROOT;

function readPackage(pkg, context) {
if (!mastraRepoRoot || pkg.name !== 'backend') {
return pkg;
}

const mastraMap = {
mastra: 'packages/cli',
'@mastra/core': 'packages/core',
'@mastra/client-js': 'client-sdks/client-js',
'@mastra/ai-sdk': 'client-sdks/ai-sdk',
'@mastra/evals': 'packages/evals',
'@mastra/mcp': 'packages/mcp',
'@mastra/memory': 'packages/memory',
'@mastra/mongodb': 'stores/mongodb',
'@mastra/otel-exporter': 'observability/otel-exporter',
'@mastra/server': 'packages/server',
};

Object.entries(mastraMap).forEach(([key, value]) => {
pkg.dependencies[key] = `link:${mastraRepoRoot}/${value}`;
});

return pkg;
}

module.exports = {
hooks: {
readPackage,
},
};
const mastraRepoRoot = process.env.MASTRA_REPO_ROOT;

function readPackage(pkg, context) {
if (!mastraRepoRoot || pkg.name !== 'backend') {
return pkg;
}

const mastraMap = {
mastra: 'packages/cli',
'@mastra/core': 'packages/core',
'@mastra/client-js': 'client-sdks/client-js',
'@mastra/ai-sdk': 'client-sdks/ai-sdk',
'@mastra/evals': 'packages/evals',
'@mastra/mcp': 'packages/mcp',
'@mastra/memory': 'packages/memory',
'@mastra/mongodb': 'stores/mongodb',
'@mastra/otel-exporter': 'observability/otel-exporter',
'@mastra/server': 'packages/server',
};

Object.entries(mastraMap).forEach(([key, value]) => {
pkg.dependencies[key] = `link:${mastraRepoRoot}/${value}`;
});

return pkg;
}

module.exports = {
hooks: {
readPackage,
},
};
LekoArts
LekoArts•2w ago
Hello! We're distributing source maps, you can see them here for example: https://app.unpkg.com/@mastra/core@0.24.6/files/dist Is that not working for you?
UNPKG
The CDN for everything on npm
LekoArts
LekoArts•2w ago
Including the src is not an option since that would dramatically increase the size and we need to be conscious of that for targets like serverless functions that have size limits
kosukeoya
kosukeoyaOP•2w ago
Hi, just having a source maps doesn't allow you to set breakpoints and directly debug your typescript files.
Ward
Ward•2w ago
@kosukeoya sorry we wont' add src files, it makes the install larger and we rather do not. sourcemaps should do enough. What are you missing here?
kosukeoya
kosukeoyaOP•2w ago
I want to be able to jump to code locations in typescript files. I frequently need to examine implementations this way, but when I navigate to minified code, I can't understand how the functions actually behave. (Moreover, I can't set breakpoints or inspect variables by inserting debugger statements.) The restriction on including source files makes sense, but how should I debug when I suspect an issue with mastra? Please share any good methods you know of.
Mastra Triager
Mastra Triager•2w ago
šŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10617 šŸ” If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. šŸ™ Thank you for helping us improve Mastra! šŸ“ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10618 šŸ” If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly. šŸ™ Thank you for helping us improve Mastra!
LekoArts
LekoArts•2w ago
I frequently need to examine implementations this way, but when I navigate to minified code, I can't understand how the functions actually behave. (Moreover, I can't set breakpoints or inspect variables by inserting debugger statements.)
We don't minify the code (if I remember correctly) so the code itself is close if not the same as the TS source just without the TS annotations. It doesn't follow the file structure but you can jump around the chunks to find what you're looking for. Adding breakpoints/debugger in node_modules works generally speaking, maybe you're invoking mastra command incorrectly and it's not triggering the debugger statements?
kosukeoya
kosukeoyaOP•2w ago
https://app.unpkg.com/@mastra/core@0.24.6/files/dist/chunk-LAQQETGP.js This is a file where the Agent class is implemented, but is it not minified? Indeed, until now I would set breakpoints in the bundled js files, inspect them, and then step through the relevant functions in the TypeScript code for debugging. Since we started minifying this has become much harder.

Did you find this page helpful?